for-each_2-input.xml
<?xml version="1.0"?>
<products>
<product
id="p1" price="3250" stock="4"/>
<product
id="p2" price="1000" stock="5"/>
</products>
for-each_2-stylesheet.xsl
<?xml version="1.0"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output
indent="yes"/>
<xsl:template
match="/">
<PRODUCTS>
<xsl:for-each
select="products/product">
<PRODUCT
id="{@id}" price="{@price}" stock="{@stock}"/>
</xsl:for-each>
</PRODUCTS>
</xsl:template>
</xsl:stylesheet>
for-each_2-output.xml
<?xml version="1.0" encoding="UTF-8"?>
<PRODUCTS>
<PRODUCT
id="p1" price="3250" stock="4"/>
<PRODUCT
id="p2" price="1000" stock="5"/>
</PRODUCTS>
This example is exactly like "xsl-for-each (1)" except that we have given the input file another structure using attributes instead of children elements in order to prepare the ground for longer examples that can fit into one page.
Updated 2009-03-19