How to use xsl:number count as condition in xsl:if test “condition”

xsltxslt-1.0

Within an xsl:for-each select loop, I have <xsl:number count="//headline"/> that correctly gives me the node #; Now I want to use that number in an xsl:if test block, but I cannot get the test expression right, msxml4.dll keeps kicking back errors. Am using xsl 1.0 (and stuck with it for now)

So, in <xsl:if test="expression">…output if the expression is true..</xsl:if>

I want the test expression to essentially be like this (so I can do something specific for Node #4, in this example):

<xsl:number count="//headline"/> = 4

This is what I have that does not work:

<xsl:if test="&lt;xsl:number count=&quot;//headline&quot;/&gt; = 4">

Thanks in advance for any insights,
George

Best Answer

If (!) I understand correctly, you want to do something like:

<xsl:variable name="n">
    <xsl:number count="headline"/>  
</xsl:variable>
<xsl:value-of select="$n"/>
<xsl:if test="$n = 4">
    <!-- do something -->
</xsl:if>
Related Topic