Learn XML, XSLT, XPath with Tutorials & Samples


xsl:copy-of
XML XSL

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="myFile.xslt"?>

<store>

  <book id="1">
    <title>XML</title>
    <author>Bill</author>
    <price>25.50</price>
  </book>

  <book id="2">
    <title>XSL</title>
    <author>Vijay</author>
    <price>75.60</price>
  </book>

  <book id="3">
    <title>HTML</title>
    <author>Kris</author>
    <price>50.40</price>
  </book>

</store>

<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html"/>

  <xsl:variable name="columnHeadings">
    <tr>
      <th>Fname</th>
      <th>Lname</th>
    </tr>
  </xsl:variable>

  <xsl:template match="/">
    <html>
      <body>
        <table border="1">
          <xsl:copy-of select="$columnHeadings" />
          <xsl:for-each select="store/book">
            <tr>
              <td><xsl:value-of select="title"/></td>
              <td><xsl:value-of select="price"/></td>
            </tr>
          </xsl:for-each>
        </table>
      </body>
    </html>
  </xsl:template>

</xsl:stylesheet>

Example : 2

OutPut:

Fname Lname
XML 25.50
XSL 75.60
HTML 50.40