Use of XSLT with XML

In this article I am going to explain about XML with XSLT.
  • 1944

XML with XSLT

XSLT stands for eXtensible Stylesheet Language Transformations. XSLT is the recommends style sheets language of XML. It is more sufficient than CSS. The root element that declares the document to be an XSL style sheet is <xsl:stylesheet> or <xsl:transform>.  For access XSLT element, attribute, and its feature we must be declared XSLT namespace top of the document. XMLT may be use for transforming XML Document in HTML Document. Its should be done before display on Browser.

Create XSLT style sheet

<?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>My Document</h2>
  <table border="1">
    <tr bgcolor="#9acd32">
      <th>Name</th>
      <th>Address</th>
    </tr>
    <xsl:for-each select="catalog/cd">
    <tr>
      <td><xsl:value-of select="Name"/></td>
      <td><xsl:value-of select="Address"/></td>
    </tr>
    </xsl:for-each>
  </table>
  </body>
  </html>
</xsl:template>

</xsl:stylesheet>

Link XSLT style sheet with XML document

 <?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?>
<catalog>
  <docu>
    <Name>Prabhat</Name>
    <Address>New Delhi</Address>
    <country>India</country>
    <company>M.C.N Solutions</company>
  </docu>
</catalog>

Further Readings

You may also want to read these related articles

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

© 2020 DotNetHeaven. All rights reserved.