January 2003
Beginner to intermediate
1200 pages
23h 42m
English
The select attribute selects only the first node that matches its selection criterion. However, what if you have multiple nodes that could match? For example, say you can have multiple <NAME> elements for each planet:
<PLANET>
<NAME>Mercury</NAME>
<NAME>Closest planet to the sun</NAME>
<MASS UNITS="(Earth = 1)">.0553</MASS>
<DAY UNITS="days">58.65</DAY>
<RADIUS UNITS="miles">1516</RADIUS>
<DENSITY UNITS="(Earth = 1)">.983</DENSITY>
<DISTANCE UNITS="million miles">43.4</DISTANCE><!--At perihelion-->
</PLANET>
The <xsl:value-of> element's select attribute by itself selects only the first <NAME> element. To loop over all possible matches, you can use the <xsl:for-each> element, like this: