I've got an xml, that I want to process, and simply label in turn each leaf node, flip or flip in turn, unless some condition is met.
take for example this xml
<root>
<tx>
<alloc>
<event>a</event>
<event>b</event>
</alloc>
<alloc>
<event>c</event>
<event>d</event>
<event>d1</event>
</alloc>
</tx>
<tx>
<alloc>
<event>e</event>
<event>f</event>
<event>g</event>
</alloc>
</tx>
</root>
and lets say we want to label each event node, flip then flip then flip, etc UNLESS the event is "e"
note the labelling of the events is independent of the hierachy.
so...
<root>
<tx>
<alloc>
<event flip="true">a</event>
<event flip="false">b</event>
</alloc>
<alloc>
<event flip="true">c</event>
<event flip="false">d</event>
<event flip="true">d1</event>
</alloc>
</tx>
<tx>
<alloc>
<event flip="true">e</event>
<event flip="false">f</event>
<event flip="true">g</event>
</alloc>
</tx>
</root>
so node "d1" is "true" AND "e" stays "true" before carrying on, because of our rule.
now...I CAN see a way to do it, but it doesnt feel as if it fits XSLT very nicely.
If I were to do this in some functional language I would recursive process the tree, basically cloning it, passing the value of flip/flop through each recursive function so something like...
so for example the tx processing template would look something like this (this is made up)
<xsl:template match="tx" mode="label">
<xsl:param name="flip_flip"/>
<xsl:variable name="allocations">
<xsl:apply-templates select="alloc" mode="label">
<xsl:with-param name="flip_flip" select="$flip_flop"/>
</xsl:apply-templates>
</xsl:variable>
<xsl:copy-of select="$allocations"/>
<xsl:variable name="new_flip_flip" select="alloc/event/@flip[last()]"
<xsl:apply-templates select="following-sibling::tx[1]" mode="label">
<xsl:with-param name="flip_flip" select="$new_flip_flip + 1"/>
</xsl:apply-templates>
</xsl:template>
i.e. process each element in turn, pull out the last calculated flip flop value, and then process the next one.
feels ugly in xslt.
another option would be to count the number of preceding events, take off the number of exceptions and then work out mod 2 if flip is true or false. again, feels clunky, and computationally expensive.