This example copies the <myElement> element and adds a copied attribute with the value "true".
Note To test this example, you need to use a script. For more information, see Initiate XSLT in a Script.
XML File (myelem.xml)
<?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="attrcopied.xsl" ?> <root> <myElement>My Data</myElement> <myElement>My Other Data</myElement> </root>
XSLT File (attrcopied.xsl)
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:template match="myElement">
<xsl:copy>
<xsl:attribute name="copied">true</xsl:attribute>
<xsl:apply-templates />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Output
This is the formatted output:
My DataMy Other Data
The following is the processor output, with line breaks added for clarity.
<?xml version="1.0"?> <myElement copied="true">My Data</myElement> <myElement copied="true">My Other Data</myElement>