Jump to content

xsl:if


dklim

Recommended Posts

<!--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

<!--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
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>

Link to comment
Share on other sites

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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...