Scrier Posted December 16, 2008 Share Posted December 16, 2008 Im looking to do a match template that I can loop up in until I find a specific node. The template I have atm looks like this: <xsl:template match="if|and|case|condition|sequence" mode="repetition"> <xsl:choose> <xsl:when test="sequence"> <!-- Do something else, we found the node --> </xsl:when> <xsl:otherwise> <xsl:apply-templates select="parent::*" mode="repetition" /> </xsl:otherwise> </xsl:choose></xsl:template> And as you probably understand the xml is nested if, and, case, condition parameters that i need to go up through to find the overlying sequence, here is an example of the tree: <sequence> <something /></sequence><validation> <case> <if> <and /> <and /> </if> </case></validation> so I can be in any underlying node on if, and etc and need to find up to the sequence nodeThe current template complains that I try to loop around ".", although I have tried parent::node() and some others but all seems to think I loop around the same element and not the overlying. Link to comment Share on other sites More sharing options...
aalbetski Posted December 16, 2008 Share Posted December 16, 2008 Based on the very limited samples you gave us, it looks like you're working too hard to get what you're after. I inferred that you are trying to find the sequence node that has a sibling validation node. Based on your example all you need to do is look for the preceding sibling. The trick here is to remember that preceding sibling is done in reverse document order, so you need to index it, otherwise you'll get the value for the first one, not the one you are looking for. All that said, here is my examples. I modified your XML into what I think you have <data> <sequence> <something>if1</something> </sequence> <validation> <case> <if> <and /> <and /> </if> </case> </validation> <sequence> <something>if2</something> </sequence> <validation> <case> <if> <and /> <and /> </if> </case> </validation> </data> XSLT <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" version="1.0"> <xsl:output method="html" /> <xsl:template match="/"> <xsl:for-each select="//validation"> <xsl:value-of select="preceding-sibling::sequence[1]/something"/> <br/> </xsl:for-each> </xsl:template> </xsl:stylesheet> result if1if2 Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.