I guess my problem is quite common, so there must be an easy solution. Consider the following xml snippet:
<categories>
<category name="cat1" />
<category name="cat2" />
<category name="cat3" />
<category name="cat4" />
</categories>
<data>
<catval name="cat2">foo</catval>
<catval name="cat4">bar</catval>
<catval name="cat3">boo</catval>
</data>
I need to output the catval values in the order defined in the categories element (including categories that have no data). Please note that in the real input xml, there are multiple data elements all over the place and the output is way more complex, so creating a template for categories is not feasible. I am using a construct like the following:
<xsl:template match="data">
<xsl:variable name="currentdata" select="." />
<xsl:for-each select="../categories/category">
<xsl:value-of select="@name" />:
<xsl:value-of
select="$currentdata/catval[@name=@name]" /> <!-- ??? -->
</xsl:for-each>
</xsl:template>
I don't know if this is the best approach to solve my problem, but even if it isn't: How can I match the name attribute of $currentdata/catval to the name attribute of the category element in the context of the for-each loop?