对于xslt-1.0,如何修改下面的代码,以便它将third
类添加到第一,第四,seveth等inner-div
元素中?
<div id="myDiv">
<xsl:for-each select="key('category', $var1)">
<div class="inner-div">
sometext
</div>
</xsl:for-each>
</div>
所以它是:
<div id="myDiv">
<div class="inner-div third">
sometext
</div>
<div class="inner-div">
sometext
</div>
<div class="inner-div">
sometext
</div>
<div class="inner-div third">
sometext
</div>
<div class="inner-div">
sometext
</div>
<div class="inner-div">
sometext
</div>
<div class="inner-div third">
sometext
</div>
</div>
谢谢。
你需要对position()
进行模算术:
<div id="myDiv">
<xsl:for-each select="key('category', $var1)">
<div>
<xsl:attribute name="class">
<xsl:text>inner-div</xsl:text>
<xsl:if test="(position() mod 3) = 1"> third</xsl:if>
</xsl:attribute>
sometext
</div>
</xsl:for-each>
</div>