我在xsl中有以下节点:
<foo>
<bar>1</bar>
<bar>2</bar>
<bar>3</bar>
<bar>4</bar>
<bar>5</bar>
<bar>6</bar>
<bar>7</bar>
<bar>8</bar>
<bar>9</bar>
</foo>
Run Code Online (Sandbox Code Playgroud)
并希望将其转换为以下html:
<ul class="one">
<li>1</li>
<li>4</li>
<li>7</li>
</ul>
<ul class="two">
<li>2</li>
<li>5</li>
<li>8</li>
</ul>
<ul class="three">
<li>3</li>
<li>6</li>
<li>9</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
很难弄清楚如何循环并获得每个第三项,想要做这样的事情:
<ul class="one">
<xsl:for-each select="exlt:node-set($blah)/foo/bar[X1]">
<li><xsl:value-of select="node()"/></li>
</xsl:for-each>
</ul>
<ul class="two">
<xsl:for-each select="exlt:node-set($blah)/foo/bar[X2]">
<li><xsl:value-of select="node()"/></li>
</xsl:for-each>
</ul>
<ul class="three">
<xsl:for-each select="exlt:node-set($blah)/foo/bar[X3]">
<li><xsl:value-of select="node()"/></li>
</xsl:for-each>
</ul>
Where:
X1 = Every third item starting from position 1
X2 = Every third item starting from position 2
X3 = Every third item starting from position 3
Run Code Online (Sandbox Code Playgroud)
可能需要使用last(),但不能完全正常工作.
小智 5
在XPath中,条件是:
not(position() mod 3)
Run Code Online (Sandbox Code Playgroud)
要么
position() mod 3 = 0
Run Code Online (Sandbox Code Playgroud)
我不明白为什么你不能使用op:mod
.
编辑:关于新问题,只需减去偏移量.所以:
X1:
position() mod 3 = 1
Run Code Online (Sandbox Code Playgroud)
X2:
position() mod 3 = 2
Run Code Online (Sandbox Code Playgroud)
X3:
position() mod 3 = 0
Run Code Online (Sandbox Code Playgroud)
编辑2:现在我理解你的问题.