I have nested xsl:for loops:
<xsl:for-each select="/Root/A">
<xsl:for-each select="/Root/B">
<!-- Code -->
</xsl:for>
</xsl:for>
From within the inner loop, how can I access attributes from the current node in the outer loop?
I keep finding myself writing code like this:
<xsl:for-each select="/Root/A">
<xsl:variable name="someattribute" select="@SomeAttribute"/>
<xsl:for-each select="/Root/B">
<!-- Now can use $someattribute to access data from 'A' -->
</xsl:for>
</xsl:for>
This doesn't scale very well, as sometimes I need to access several pieces of information and end up creating one variable for each piece. Is there an easier way?
The following could also be used :
For parsing the XML document ..
You can store the entire /Root/A structure in a variable, and make reference to that variable rather than creating a new variable for every attribute and subelement you need to access.
Welbog has answered it well - but just to note you appear to be doing a cartesion (cross) join - is that intentional? If you are trying to do a regular join (with a predicate etc), then you want want to look into
<xsl:key/>
- i.e. declare a key:then consume in your predicate:
This should be equivalent to (but much faster than) the predicate:
If you are grouping the data, then look at Muenchian grouping