I have a for-each I want to sort by some value. But the thing I loop over only has a key that allows a connection to the value. A simple example for a document:
<foo>
<keys>
<key id="foo"/>
<key id="bar"/>
</keys>
<things>
<thing name="foo"><desc>some description</desc></thing>
<thing name="bar"><desc>another description</desc></thing>
</things>
</foo>
And a style sheet:
<xsl:for-each select="/foo/keys/key">
<xsl:sort select="/foo/things/thing[@name=@id]"/>
<xsl:value-of select="@id"/>
</xsl:for-each>
This doesn't seem to work. @id relates to the key element from the loop; @name relates to thing from the predicate. How do I solve this? I tried assigning /foo/keys/key/@id to a variable and use that but <sort> must be the first element in a for-each...