- The CDs themselves have an artist and title fields.
- So it should be possible to search for CDs of a particular artist
- The key is the contents of the artist field
- In this case the key may return a set of artist nodes
- Use xsl:for-each to go through these finding the contents of the associated title element
<xsl:key name="lookupartist" match="cd/artist" use="." />
<xsl:key name="pricekey" match="price" use="@ticket" />
<xsl:template match="/cdlist">
<h3>CDs by Louis Armstrong</h3>
<xsl:for-each select="key('lookupartist','Armstrong, Louis')" >
<pre><text>Title: </text><xsl:value-of select="../title" />
<xsl:variable name="pricecolor" select="../@price" />
<text> ,Price: </text><xsl:value-of select="key('pricekey' , $pricecolor)" />
</pre>
</xsl:for-each>
</xsl:template>
Result