0
votes

Lets say I have the following xsl:template element:

<xsl:template name="acct-row-l3">
  <xsl:param name="category" as="element()"/>
  <xsl:for-each-group select="$category" group-by="concat(ACCT_3, '|', ACCT3_DESC)">
  . . .
  </xsl:for-each-group>
</xsl:template>

and I want to change it to allow me to pass in an account level so that the group-by="concat(ACCT_3, '|', ACCT3_DESC)" portion of the template can by dynamic. something like this:

group-by="concat($acct, '|', $acct-desc)"

Is there are a way to do this?

1
The code looks a bit odd, you have category typed as a single element() node but then try to group that single element node by a string formed with a concat() call? I don't understand what kind of grouping that would achieve. As for variable references in the concat calll, well, that is of course possible but more mysterious in my view as it groups on a string value not even based on XPath selection related to the $category. Perhaps show us some input samples and how you want to group them and the whole approach is clearer. Perhaps you look for xsl:evaluate but that needs XSLT 3 - Martin Honnen
And as with all things perhaps needing xsl:evaluate, the simple case of simply selecting a child element by name can usually expressed as a predicate comparing the node name concat(*[local-name() = $acct], '|', *[local-name() = $acct-desc]). - Martin Honnen

1 Answers

0
votes

In XSLT 3 with function expressions (e.g. as supported in Saxon 10 all editions or Saxon 9.8 or 9.9 EE and PE) the cleanest approach might be to parameterize the group-by as a function:

<xsl:param name="group-by" as="function(item()) as item()*"/>

and

<xsl:for-each-group select="..." group-by="$group-by(.)">...</xsl:for-each-group>

where you can then pass in e.g <xsl:with-param name="group-by" select="function($c) { concat($c/foo, '|', $c/bar) }"/> or <xsl:with-param name="group-by" select="function($c) { concat($c/acc1, '|', $c/desc1) }"/>.