yas
yas

Reputation: 3620

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

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.

Upvotes: 1

Views: 4884

Answers (2)

Ali Soltani
Ali Soltani

Reputation: 9946

I think this code can help you:

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

Upvotes: 0

michael.hor257k
michael.hor257k

Reputation: 117175

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.

Upvotes: 4

Related Questions