我想创建一个HTML表与行颜色变化的位置和内容为基础。但我希望能够将行组合在一起,这样我就可以拥有一些如下的XML,而不是交替每行:
<itemlist>
<item group="0">Conent...blah blah</item>
<item group="0">Content...who cares</item>
<item group="1">Content</item>
<item group="2">Content</item>
<item group="2">Content</item>
</itemlist>所有带有group=0的项目都是一种颜色,带有group=1的项目是另一种颜色,而group=2要么切换回第一种颜色,要么是它们自己的颜色。
我所能找到的似乎是每一行都有交替的方法,但是当涉及到实际使用节点数据来帮助我做出决定时,我似乎不能“得到它”。
发布于 2008-11-01 03:14:55
下面是一个使用"choose“根据组值应用不同类值的示例。如果你想以一种特定的方式对待每一组,那么类似的方法将会起作用。如果处理组2的决策逻辑比较复杂,那么可以将附加的决策逻辑放在组2的"when“语句测试中。
<xsl:template match="/">
<ul>
<xsl:apply-templates select="itemlist/item"/>
</ul>
</xsl:template>
<xsl:template match="item">
<li>
<xsl:attribute name="class">
<xsl:choose>
<xsl:when test="@group = 0">
red
</xsl:when>
<xsl:when test="@group = 1">
green
</xsl:when>
<xsl:when test="@group = 2">
blue
</xsl:when>
<xsl:otherwise>
black
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:value-of select="."/>
</li>
</xsl:template>https://stackoverflow.com/questions/255422
复制相似问题