attribute_1-input.xml
<?xml version="1.0"?>
<products>
<product
id="p1">
<name>Delta</name>
<stock>4</stock>
</product>
</products>
attribute_1-stylesheet.xsl
<?xml version="1.0"?>
<xsl:stylesheet
version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output
indent="yes"/>
<xsl:template
match="/">
<xsl:element
name="Products">
<xsl:element
name="Product">
<xsl:attribute
name="id"><xsl:value-of
select="products/product/@id"/></xsl:attribute>
<xsl:element
name="Name">
<xsl:value-of
select="products/product/name"/>
</xsl:element>
<xsl:element
name="Stock">
<xsl:value-of
select="products/product/stock"/>
</xsl:element>
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
attribute_1-output.xml
<?xml version="1.0" encoding="UTF-8"?>
<Products>
<Product
id="p1">
<Name>Delta</Name>
<Stock>4</Stock>
</Product>
</Products>
In XSLT 2.0 we could also have said:
<xsl:attribute name="id" select="products/product/@id"/>
Updated 2009-03-19