我不知道如何计算具有给定名称的节点的出现次数。
这是我的结构:
<xsl:variable name="pageType" select="/verticaldata/context/querystring/parameter[@name = 'type']"/>
<xsl:template match="/">
<xsl:if test="number(/verticaldata/contents/@totalcount) > 0">
<xsl:apply-templates select="verticaldata/contents/content"/>
</xsl:if>
</xsl:template>
<xsl:template match="content">
<xsl:variable name="itemType" select="contentdata/type">
<xsl:if test="$pageType = $itemType">
<xsl:call-template name="displayItem"/>
</xsl:if>
</xsl:template>
<xsl:template name="displayItem">
<!-- Here I want to show the item number in the id -->
<div class="item">
<xsl:attribute name="id">
<xsl:value-of select="count(preceding-sibling::content)"/>
</xsl:attribute>
<!-- Item renders here -->
</div>
</xsl:template>
我已经尝试过 position() 和 count(preceding-sibling::content) 但它们都显示了总数而不是通过“类型”检查的项目数。如何获取之前创建的“displayItem”节点的计数?
这可能吗?
//丹尼尔