The fact that you can not reassign a variable in XSL is an endless
source of frustration, causing you to jump through all sorts of
non-intuitive hoops.
In this case, however, the lack of reassignment has me totally
perplexed on how to achieve a solution to the following problem:
(These are illustrative fragments)
XML:
<item id="0" name="item0">
<event description="item0_event0"/>
<event description="item0_event1"/>
</item>
<item id="1" name="item1">
<event description="item1_event0"/>
<event description="item1_event1"/>
</item>
XSL: (Incorrect, this is what I'm trying to figure out)
<xsl:for-each select="item">
<xsl:variable name="baseRow" select="position()"/>
<row>
<xsl:attribute name="index"><xsl:value-of
select="$baseRow"/></xsl:attribute>
<cell index="0">
<xsl:value-of select="@id"/>
</cell>
<cell index="1">
<xsl:value-of select="@name"/>
</cell>
</row>
<xsl:for-each select="event">
<row>
<xsl:attribute name="index"><xsl:value-of select="$baseRow
+ position()"/></xsl:attribute>
<cell index="0">
<xsl:value-of select="@description"/>
</cell>
</row>
</xsl:for-each>
<!-- <xsl:variable name="baseRow" select="$baseRow +
count(event)"/> --> <!-- Pseudocode -->
</xsl:for-each>
DESIRED OUTPUT AFTER XFORM:
<row index="0">
<cell index="0">0</cell>
<cell index="1">item0</cell>
</row>
<row index="1">
<cell index="0">item0_event0"</cell>
</row>
<row index="2">
<cell index="0">item0_event1"</cell>
</row>
<row index="3">
<cell index="0">1</cell>
<cell index="1">item1</cell>
</row>
<row index="4">
<cell index="0">item1_event0"</cell>
</row>
<row index="5">
<cell index="0">item1_event1"</cell>
</row>
Notice how the row index is continuously incremented. This is my
desired output, however I cannot figure out how to accomplish it.
Essentially I like to increment the base position() of the first
for-each by the count() of the second for-each at the end of the first
loop.
Thanks for any insight you can provide.