Search code examples
xsltxslt-grouping

XSLT grouping-key of the parent group


I have 3 nested xsl:for-each-group statements and i'm using a variable to store the parent's current-grouping-key(), because i need this value in the last for-each-group as a filter. but i'm wondering if it's not possible to access the parent's current-grouping-key somehow else without declaring a specific variable?

Example:

<xsl:for-each-group select="//results/result[measuring_plane != '']" group-by="inspection_feature">

  <xsl:variable name="v_current_inspection_feature" select="inspection_feature" as="xs:string"/>

  <xsl:for-each-group select="//results/result[inspection_feature = current-grouping-key() and measuring_plane != '']" group-by="description">

    <xsl:for-each-group select="//results/result[inspection_feature = $v_current_inspection_feature and description = current-grouping-key() and measuring_plane != '']" group-by="step">

SOLUTION:

<xsl:for-each-group select="//results/result[measuring_plane != '']" group-by="inspection_feature">
  <xsl:for-each-group select="current-group()" group-by="description">
    <xsl:for-each-group select="current-group()" group-by="step">

Solution

  • Use select="current-group()" for the nested for-each-group instructions.