我需要能够计算兄弟元素有多少个子节点。我需要根据下一个锚标记是否有任何子节点,在锚标记上将CSS类更改为“no_border”。
到目前为止我所拥有的是:
<xsl:for-each select="Menu/Item">
<li>
<a>
<xsl:attribute name="class">
<xsl:if test="following-sibling::Item/count(Menu/Item)">
no_border
</xsl:if>
</xsl:attribute>
<xsl:value-of select="ItemTitle />
</a>
</li>
</xsl:for-each>
Visual Studio告诉我:
错误1表达式的预期结束,找到'('。follow-sibling :: Item / count - &gt;(&lt; - Menu / Item)C:\ Projects ** \ XmlFiles \ xslt \ SiteMap.xslt 78 74 C:\ Projects * * \
所以看起来我不能在“follow-sibling”之后加上“count()”命令。
以下是XML示例:
<root>
<Item>
<Menu>
<Item>
... other sub-nodes
</Item>
</Menu>
</Item>
<Item>
<Menu>
<Item>
... other sub-nodes
</Item>
</Menu>
</Item>
</root>
编辑:我找到了解决方案:
<xsl:if test="count(following-sibling::Item/Menu/Item) = 0" >