Stephen Welker wrote:

> I have a problem with following XSL code...
>
> <xsl:template match="sub-section">
>  <DIV>
>   <xsl:if test="number(/text/sub-section-hilite)">
>    <xsl:if test="position() mod 2 = 0">
>     <xsl:attribute name="CLASS">subsectionhilite</xsl:attribute>
>    </xsl:if>
>   </xsl:if>
>   <xsl:apply-templates mode="sub-section"/>
>  </DIV>
> </xsl:template>
>
> It is based on the following code snippet from W3C.
>
> <xsl:template match="item">
>  <tr>
>   <xsl:if test="position() mod 2 = 0">
>    <xsl:attribute name="bgcolor">yellow</xsl:attribute>
>   </xsl:if>
>   <xsl:apply-templates/>
>  </tr>
> </xsl:template>
>
> My problem is that the test="position() mod 2 = 0" evaluates to true all
> the time.
>
> My XML has more than 1 "sub-section" node (common parent) and is well
> formed.
>
> Any suggestions?

Have you tried looping through the sub-sections?

<xsl:template match="sub-section">
<xsl:for-each select=".">
 <DIV>
  <xsl:if test="number(/text/sub-section-hilite)">
   <xsl:if test="position() mod 2 = 0">
    <xsl:attribute name="CLASS">subsectionhilite</xsl:attribute>
   </xsl:if>
  </xsl:if>
  <xsl:apply-templates mode="sub-section"/>
 </DIV>
</xsl:for-each>
</xsl:template>

* Note extra for-each lines!
Better?

--
Mark McLaren
Viva Napster

Reply via email to