Nested for-each-group with current-group() referenced in for-each-group/@select
authorMichael Kay <mike@saxonica.com>
Wed, 13 Jun 2018 12:34:38 +0100
changeset 1853 0da0f4567f4b
parent 1852 60fb2cad43a4
child 1854 34b81d40f96b
Nested for-each-group with current-group() referenced in for-each-group/@select
tests/insn/for-each-group/_for-each-group-test-set.xml
tests/insn/for-each-group/for-each-group-088.xsl
--- a/tests/insn/for-each-group/_for-each-group-test-set.xml	Wed Jun 13 12:33:36 2018 +0100
+++ b/tests/insn/for-each-group/_for-each-group-test-set.xml	Wed Jun 13 12:34:38 2018 +0100
@@ -1497,4 +1497,21 @@
          <assert-xml file="for-each-group-043.out"/>
       </result>
    </test-case>
+   
+   <test-case name="for-each-group-088">
+      <description>Reference current-group() in for-each-group/@select</description>
+      <created by="Michael Kay" on="2018-07-07"/>
+      <environment ref="group029"/>
+      <dependencies>
+         <spec value="XSLT20+"/>
+      </dependencies>
+      <test>
+         <stylesheet file="for-each-group-088.xsl"/>
+      </test>
+      <result>
+         <all-of>
+            <assert>/table/pop[@value='5']/deep-equal(data(city/@name), ('milan', 'bristol', 'sheffield'))</assert>
+         </all-of>
+      </result>
+   </test-case>
 </test-set>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/insn/for-each-group/for-each-group-088.xsl	Wed Jun 13 12:34:38 2018 +0100
@@ -0,0 +1,16 @@
+<?spec xslt#grouping?>
+<xsl:transform version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+  xmlns:xs="http://www.w3.org/2001/XMLSchema">
+  <xsl:template match="/">
+    <table>
+      <!-- Reference current-group() within group-by expression -->
+      <xsl:for-each-group select="cities/city" group-by="xs:decimal(@pop)">
+        <pop value="{current-grouping-key()}">
+          <xsl:for-each-group select="current-group()" group-by="@name[../@pop = current-group()/@pop]">
+            <city name="{@name}"/>
+          </xsl:for-each-group>
+        </pop>
+      </xsl:for-each-group>
+    </table>
+  </xsl:template>
+</xsl:transform>