Count size of set iterated by XSLT for-each-group

2019-08-01 08:29发布

问题:

I am writing a XSLT stylesheet that generates another XSLT stylesheet.

In one part of the code, I am iterating / grouping elements:

<xsl:for-each-group
    select="descendant::FormSectionElements[not(LoadBindBase = '')]" 
    group-by="concat(LoadBindBase,SubmitBindBase)">

     ...

</xsl:for-each-group>

In another area in the template, which is nested at a different level, I need to obtain the number of items which would have been iterated by the above loop.

Is there an XPath expression that can count the size of the set that would be iterated by for-each-group? In this other area of the template, I am able to obtain the same elements as in the select attribute of the for-each-group.

回答1:

an XPath expression that can count the size of the set that would be iterated by for-each-group?

count(current-group())

will return the size of the current group and:

last()

will return the number of groups.



回答2:

I think this code can help you:

<xsl:value-of select="count(descendant::FormSectionElements[not(LoadBindBase = '')])" />


标签: xml xslt xpath