I have an XSLT 2.0 stylesheet. I need to perform a for-each-group loop, but the value I am grouping on may change, based on parameters passed into the stylesheet.
For example, if my XML looks like this (simplified for this example):
<root><row><date>2001-01-01</date><text>abc</text></row><row><date>2003-04-02</date><text>xyz</text></row>...</root>
I want to perform a for-each-group, grouping on a function applied to the date node. for example, it might be this:
<xsl:for-each-group select="/root/row" group-by="substring(date,1,4)">
or this:
<xsl:for-each-group select="/root/row" group-by="substring(date,1,7)">
I might even need to group on a different node, like . So I could use:
<xsl:for-each-group select="/root/row" group-by="$variable">
Is there any way to define a variable with the function and node I want to group on and then use that variable in the group-by expression? or some other way to do this? I tried using a simple variable, but that did not work, both (the second is inside single quotes):
<xsl:variable name="variable" select="substring(date,1,4)"/>
and
<xsl:variable name="variable" select="'substring(date,1,4)'"/>
I have a related question, but it likely has the same answer. I also need to perform an where the select will also need to use this same variable, like:
<xsl:value-of select="/root/row/$variable"/>
Thanks!