我有一个XML文件等如下:XSL:计数连续属性
<Query>
<Rows>
<Row Pd="1"></Row>
<Row Pd="1"></Row>
<Row Pd="0"></Row>
<Row Pd="0"></Row>
<Row Pd="0"></Row>
<Row Pd="0"></Row>
<Row Pd="1"></Row>
<Row Pd="1"></Row>
<Row Pd="1"></Row>
<Row Pd="1"></Row>
<Row Pd="1"></Row>
<Row Pd="1"></Row>
<Row Pd="1"></Row>
<Row Pd="0"></Row>
<Row Pd="0"></Row>
<Row Pd="0"></Row>
<Row Pd="1"></Row>
<Row Pd="1"></Row>
<Row Pd="1"></Row>
</Rows>
</Query>
这是用“PD”属性项的基本上的有序列表(值= 0或1)。 我需要显示的结果如下:
- 用Pd = 1的行的总数,
- 用Pd = 1(0,如果最新的Pd = 0)
- 最大数目最新连续的行的用PD =
连续行的意甲我设法得到1和2,但未能达到3
我1 & 2(XSLT 1.0)溶液:
<xsl:output method="html" indent="yes"/>
<xsl:template match="/">
<div>
<h1>total # of Pd1 : <xsl:value-of select="sum(//Row/@Pd)"/></h1>
<h1># of consecutive Pd1: <xsl:apply-templates/> </h1>
</div>
</xsl:template>
<xsl:template match="//Row[not(following-sibling::Row[1]/@Pd=self::Row/@Pd)][1]">
<xsl:value-of select="sum(self::Row[1]/@Pd|preceding-sibling::Row/@Pd)"/>
</xsl:template>
</xsl:stylesheet>
对于上面引述的XML,预期的结果应该是:
欢迎提供针对问题3的解决方案的任何帮助(以及对提供的其他解决方案的改进)
您可以使用XSLT 2.0和这样'XSL :for-each-group select =“// Row”group-adjacent =“@ Pd”'? –
不幸的是,只有XSLT 1.0 ...即使分组是一回事,在这些组中获得最长的序列也不会那么容易。 – Tang