I am trying to select all the nodes that 1) come after a node with a specific property and 2) have a specific property. Therefore, 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 goes through the node tag. On each node I want it to select all previous node that came from the very last node that had a child , whose attr was valueOfInterest . Therefore, if I were in node # 2, I need an empty node set. If I were in node # 6, I would like to select node # 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 the previous attr values, which are a specific value. How to get only those that precede attr values ββthat are in the node that appear after the last node that child has a specific attr value (ie "ValueOfInterest")? The id attribute in the node tags does not guarantee an increase, so we cannot compare with this.
Edit: I thought they could be useful:
<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, all the previous child tags with attr=valueOfInterest , and then the most recent (closest to the current node tag) child tag that has the attribute I'm looking for. From mru_child_of_interest we can find the last used parent tag, but how can we look for nodes that appear after this tag?
source share