I'm trying to select all nodes that 1) come after a node with a particular property and 2) have a particular property themselves. So if I had the following XML:
<node id="1"><child attr="valueOfInterest"/></node>
<node id="2"><child attr="boringValue"/></node>
...
<node id="3"><child attr="valueOfInterest"/></node>
<node id="4"><child attr="boringValue"/></node>
<node id="5"><child attr="boringValue"/></node>
<node id="6"><child attr="boringValue"/></node>
...
My XSLT traverses through each node
tag. At each node
, I want it to select all previous node
s that occurred since the most recent node
that had a child
whose attr
was valueOfInterest
. So if I were at node #2, I would want an empty node set. If I were at node #6, I would want to select node #'s 4 and 5. I currently have the following XSLT:
<xsl:variable name="prev_vals"
select="preceding-sibling::node/child[@attr = $someValueICareAbout]/@attr"/>
So this XSLT gets all preceding attr
values that are a particular value. How do I only get those preceding attr
values that are in node
s that come after the most recent node
whose child
has a particular attr
value (i.e., "valueOfInterest")? The id
attribute on node
tags is not guaranteed to be increasing, so we can't compare against that.
Edit: I thought these might be of use:
<xsl:variable name="prev_children_of_interest"
select="preceding-sibling::node/child[@attr != $someValueICareAbout]"/>
<xsl:variable name="mru_child_of_interest"
select="$prev_children_of_interest[count($prev_children_of_interest)]"/>
So that's all previous child
tags with attr=valueOfInterest
and then the most recently used (closest to current node) child
tag that has the attribute I'm looking for. From mru_child_of_interest
we can find the most recently used parent
tag, but how do we then look for nodes that come after that tag?