dklim Posted February 27, 2007 Share Posted February 27, 2007 <!--Here is a snipet of xslt code.--><xsl:template match="/"><xsl:apply-templates select="level2"/></xsl:template><xsl:template match="level2"><xsl:if test="following-sibling::NOTE"><note><para>!!!!TEST IS TRUE!!!!</para></note></xsl:if><!--Here is a snipet of xml.--><level2></level2><StepLevel3></StepLevel3><level2></level2><NOTE></NOTE>What happens is that true is returned for the first and second <level2> because <NOTE> is a sibling. I need the first <level2> to return a false because the next node is not <NOTE> and the second <level2> a true. I need to test for <NOTE> right next to the current node not any sibling. Can't seem to find it.Thanks Link to comment Share on other sites More sharing options...
boen_robot Posted February 27, 2007 Share Posted February 27, 2007 <!--Here is a snipet of xslt code.--><xsl:template match="/"><xsl:apply-templates select="level2"/></xsl:template><xsl:template match="level2"><xsl:if test="following-sibling::NOTE"><note><para>!!!!TEST IS TRUE!!!!</para></note></xsl:if><!--Here is a snipet of xml.--><level2></level2><StepLevel3></StepLevel3><level2></level2><NOTE></NOTE>What happens is that true is returned for the first and second <level2> because <NOTE> is a sibling. I need the first <level2> to return a false because the next node is not <NOTE> and the second <level2> a true. I need to test for <NOTE> right next to the current node not any sibling. Can't seem to find it.ThanksI remember facing a similar situation once. Try this:<xsl:template match="level2"><xsl:variable name="level2pos" select="position()"/><xsl:if test="following-sibling::NOTE[position() = $level2pos + 1]"><note><para>!!!!TEST IS TRUE!!!!</para></note></xsl:if> Link to comment Share on other sites More sharing options...
dklim Posted February 28, 2007 Author Share Posted February 28, 2007 I remember facing a similar situation once. Try this:<xsl:template match="level2"><xsl:variable name="level2pos" select="position()"/><xsl:if test="following-sibling::NOTE[position() = $level2pos + 1]"><note><para>!!!!TEST IS TRUE!!!!</para></note></xsl:if> Thanks for the help. The code sugestion worked but with a different xml scenerio it did not.<level2></level2><NOTE></NOTE><level2></level2><StepLevel3></StepLevel3><level2></level2><NOTE></NOTE><level2></level2><StepLevel3></StepLevel3>In this case the if statement was true for the first <NOTE> found after a <level2> but it did not find the 2nd <NOTE> as true.Thanks Link to comment Share on other sites More sharing options...
aalbetski Posted February 28, 2007 Share Posted February 28, 2007 try this xslt <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <xsl:apply-templates select="descendant::level2"/> </xsl:template> <xsl:template match="level2"> <xsl:if test="name(following::*) = 'NOTE'"> <note><para>!!!!TEST IS TRUE!!!!</para></note><br/> </xsl:if> </xsl:template></xsl:stylesheet> Link to comment Share on other sites More sharing options...
dklim Posted March 1, 2007 Author Share Posted March 1, 2007 Thanks aalbetski the code worked! An interesting point though is I get an error when the xslt version is 2.0 but it works fine with 1.0 using xmlSpy. I'll use 1.0.Thanks all. Link to comment Share on other sites More sharing options...
boen_robot Posted March 2, 2007 Share Posted March 2, 2007 In XSLT 2.0, XPath axes are deprecated (as far as I've read). Perhaps that is why it's not working. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now