More for-each-group tests
authorMichael Kay <mike@saxonica.com>
Mon, 03 Jul 2017 10:05:53 +0100
changeset 1705 0571d34314d2
parent 1704 f7913b66fd37
child 1706 e51dc47f504f
More for-each-group tests
tests/insn/for-each-group/_for-each-group-test-set.xml
tests/insn/for-each-group/for-each-group-084.xml
tests/insn/for-each-group/for-each-group-084.xsl
tests/insn/for-each-group/for-each-group-085.xml
tests/insn/for-each-group/for-each-group-085.xsl
--- a/tests/insn/for-each-group/_for-each-group-test-set.xml	Tue Jun 27 11:49:15 2017 +0100
+++ b/tests/insn/for-each-group/_for-each-group-test-set.xml	Mon Jul 03 10:05:53 2017 +0100
@@ -1423,4 +1423,41 @@
             ></Notifications>]]></assert-xml>
       </result>
    </test-case>
+   
+   <test-case name="for-each-group-084">
+      <description>Call on last() within for-each-group/@group-starting-with</description>
+      <created by="Michael Kay after Ken Holman" on="2017-06-29"/>
+      <environment>
+         <source role="." file="for-each-group-084.xml"/>
+      </environment>
+      <dependencies>
+         <spec value="XSLT20+"/>
+      </dependencies>
+      <test>
+         <stylesheet file="for-each-group-084.xsl"/>
+      </test>
+      <result>
+         <all-of>
+            <assert>/result/local/variable-def/variable = "a "</assert>
+            <assert>/result/local/variable-def/para/text = "is an estimate of the border processing costs for the levy period, as adjusted under subclause (2)"</assert>
+         </all-of>
+      </result>
+   </test-case>
+   
+   <test-case name="for-each-group-085">
+      <description>reference to current-group() within a variable</description>
+      <created by="Michael Kay after Vladimir Nestorovsky" on="2017-06-29"/>
+      <environment>
+         <source role="." file="for-each-group-085.xml"/>
+      </environment>
+      <dependencies>
+         <spec value="XSLT20+"/>
+      </dependencies>
+      <test>
+         <stylesheet file="for-each-group-085.xsl"/>
+      </test>
+      <result>
+         <assert-xml><![CDATA[<out><t n="T"><tt n="U"/><tt n="U"/></t><t n="U"><tt n="U"/><tt n="U"/></t><t n="V"><tt n="U"/><tt n="U"/></t><t n="W"><tt n="U"/><tt n="U"/></t></out>]]></assert-xml>
+      </result>
+   </test-case>
 </test-set>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/insn/for-each-group/for-each-group-084.xml	Mon Jul 03 10:05:53 2017 +0100
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<styledDocument agency.code="PCO">
+   <_Body type="sdt">
+      <_Equationdefinitiontext type="p">a <__TAB/>is an estimate of the border processing costs for the levy period, as adjusted under subclause (2)</_Equationdefinitiontext>
+      <_Equationdefinitiontext type="p">b <__TAB/>is an estimate of the number of travellers who will arrive on Mars in the levy period, excluding cruise ship travellers and exempt travellers.</_Equationdefinitiontext>
+   </_Body>
+   <_Promulgationadminoffice type="p"/>
+</styledDocument>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/insn/for-each-group/for-each-group-084.xsl	Mon Jul 03 10:05:53 2017 +0100
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+  xmlns:k="urn:X-Ken"
+  exclude-result-prefixes="xsd k"
+  version="3.0">
+
+<k:test>
+  <_Equationdefinitiontext type="p">a <__TAB/>is an estimate of the border processing costs for the levy period, as adjusted under subclause (2)</_Equationdefinitiontext>
+</k:test>
+
+<xsl:template match="/">
+  <result>
+    <local>
+      <xsl:apply-templates select="document('')/*/k:test/*"/>
+    </local>
+  </result>
+</xsl:template>
+  
+<xsl:template match="_Equationdefinitiontext">
+  <variable-def>
+    <xsl:for-each-group select="node()" 
+                    group-starting-with="__TAB[not(preceding-sibling::__TAB)]">
+      <xsl:comment select="'DEBUG',last(),position(),current-group()!string(.)"/>
+      <xsl:choose>
+        <xsl:when test="last()=1">
+          <!--then there is no variable marked up-->
+          <variable/>
+          <para><text>
+            <xsl:apply-templates select="current-group()"/>
+          </text></para>
+        </xsl:when>
+        <xsl:when test="position()=1">
+          <!--then this must be the variable-->
+          <variable><xsl:apply-templates select="current-group()"/></variable>
+        </xsl:when>
+        <xsl:otherwise>
+          <!--then this must be the description starting with TAB-->
+          <para><text>
+            <xsl:apply-templates select="current-group()[position()>1]"/>
+          </text></para>
+        </xsl:otherwise>
+      </xsl:choose>
+    </xsl:for-each-group>
+  </variable-def>
+</xsl:template>
+
+</xsl:stylesheet>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/insn/for-each-group/for-each-group-085.xml	Mon Jul 03 10:05:53 2017 +0100
@@ -0,0 +1,6 @@
+<c>
+   <t n="T"/>
+   <t n="U"/>
+   <t n="V"/>
+   <t n="W"/>
+</c>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/insn/for-each-group/for-each-group-085.xsl	Mon Jul 03 10:05:53 2017 +0100
@@ -0,0 +1,45 @@
+<xsl:stylesheet version="2.0" 
+  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
+  xmlns:xs="http://www.w3.org/2001/XMLSchema"
+  exclude-result-prefixes="#all">
+  
+  <xsl:template match="/">
+    <out>
+      <xsl:apply-templates/>
+    </out>
+  </xsl:template>
+  
+  <xsl:template match="/c">
+    <xsl:variable name="c" as="element()*" select="*[2]"/>
+    
+    <xsl:variable name="t" as="element()*">
+      <tt n="T"/>
+      <tt n="U"/>
+      <tt n="T"/>
+      <tt n="U"/>
+      <tt n="T"/>
+    </xsl:variable>
+    
+    <xsl:variable name="o" as="element()*">
+      <xsl:for-each-group select="$t" group-by="@n">
+        <xsl:variable name="g" as="element()+" 
+          select="current-group()"/>
+        
+        <xsl:sequence select="$g[@n = $c/@n]"/>
+      </xsl:for-each-group>
+    </xsl:variable>
+    
+    <xsl:apply-templates>
+      <xsl:with-param name="o" tunnel="yes" select="$o"/>
+    </xsl:apply-templates>
+  </xsl:template>
+  
+  <xsl:template match="t">
+    <xsl:param name="o" tunnel="yes" as="element()*"/>
+    <xsl:copy>
+      <xsl:copy-of select="@*"/>
+      <xsl:copy-of select="$o"/>
+    </xsl:copy>   
+  </xsl:template>
+  
+</xsl:stylesheet>
\ No newline at end of file