articles

Home / DeveloperSection / Articles / XML Control in ASP.Net

XML Control in ASP.Net

Pushpendra Singh12409 22-Oct-2010

The XML control is used to display an XML document. XSLT document is used to format the XML document. You can format the XML document with the Transform property.

Code:

<asp:Xml ID="Xml1" runat="server" DocumentSource="~/XMLFile.xml" TransformSource="~/XSLTFile2.xslt" Visible="true">
</asp:Xml>

 

In DocumentSource propertyspecify the xml file name which data you want to show on the page. And in TransformSource specify the  xslt file name which format tha xml document.

XMLFile.xml

<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="XSLTFile.xslt"?>
<Country>
  <cd>
  <State>U.P.</State>
  </cd>
  <cd>
  <State>M.P.</State>
  </cd>
  </Country>

 

XSLT is used to transform an XML document into another XML document.XSL stands for EXtensible Stylesheet Language.XSLT is for XSL Transformations.

XSLTFile2.xslt

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <html>
      <body>
        <h2>State in India</h2>
        <table border="1">
          <tr bgcolor="#9acd32">
            <th>State </th>
          </tr>
          <xsl:for-each select="Country/cd">
            <tr>
              <td>
                <xsl:value-of select="State" />
              </td>      
            </tr>
          </xsl:for-each>
        </table>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>

 

 Run the project

 

XML Control in ASP.Net


Updated 04-Apr-2020

Leave Comment

Comments

Liked By