In the following code snippet, I have 3 for-each’s but it seems to me they ought to be able to combine into one. It works as is, but I was wondering if anyone knew of a more elegant way to write it?
<xsl:for-each select="/essentials/webservice">
<xsl:for-each select="document(@filename)/productSearchResponse/products/product">
<xsl:sort select="producingRegion" order="ascending"/>
<xsl:for-each select="producingRegion[not(preceding::producingRegion=.)]">
<xsl:value-of select="."/>
<br/>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
It’s hard to give an answer without knowing the expected result and structure of the input XML, but I believe this should work.
Edit: I just noticed that document(@filename) is a function call, not a node test. In that case, I think you need two
for-eaches.You can make it a little more concise by using a double slash in the XPath expression, though I tend to think that’s not a very good practice: