Learn XML, XSLT, XPath with Tutorials & Samples


xsl:copy
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="xml" indent="yes" omit-xml-declaration="yes"/>

  <xsl:template match="//book">
    <xsl:copy use-attribute-sets="attSet"/>
  </xsl:template>
 
  <xsl:attribute-set name="attSet">
    <xsl:attribute name="Tech">
      <xsl:value-of select="title"/>
    </xsl:attribute>
    <xsl:attribute name="Person">
      <xsl:value-of select="author"/>
    </xsl:attribute>
    <xsl:attribute name="Value">
      <xsl:value-of select="price"/>
    </xsl:attribute>
  </xsl:attribute-set>

</xsl:stylesheet>


OutPut:

  <book Tech="XML" Person="Bill" Value="25.50" />
  <book Tech="XSL" Person="Vijay" Value="75.60" />
  <book Tech="HTML" Person="Kris" Value="50.40" />