More tests for absorbing stylesheet functions
authorMichael Kay <mike@saxonica.com>
Mon, 03 Jul 2017 10:06:18 +0100
changeset 1706 e51dc47f504f
parent 1705 0571d34314d2
child 1707 11e0f57eb54a
More tests for absorbing stylesheet functions
tests/strm/su-absorbing/_su-absorbing-test-set.xml
tests/strm/su-absorbing/su-absorbing-202.xml
tests/strm/su-absorbing/su-absorbing-202.xsl
tests/strm/su-absorbing/su-absorbing-203.xsl
--- a/tests/strm/su-absorbing/_su-absorbing-test-set.xml	Mon Jul 03 10:05:53 2017 +0100
+++ b/tests/strm/su-absorbing/_su-absorbing-test-set.xml	Mon Jul 03 10:06:18 2017 +0100
@@ -235,6 +235,40 @@
       </result>       
    </test-case>
    
+   <test-case name="su-absorbing-202">
+      <description>Absorbing function - (Saxon NPE - Saxon bug 3325)</description>
+      <created by="Michael Kay after Martin Honnen" on="2017-06-29"/>
+      <environment>
+         <source file="su-absorbing-202.xml" role="." streaming="true"/>
+      </environment>
+      <test>
+         <stylesheet file="su-absorbing-202.xsl"/>
+      </test>
+      <result>
+         <assert-xml><![CDATA[<Items Title="Title" Icon="Icon" Description="Description"><Item Value="01" Name="Agriculture"
+            ><Item Value="011" Name="Horticulture and Fruit Growing"><Item Value="0111" Name="Plant Nurseries"
+            ><Item Value="011101" Name="Bulb Propagating"/></Item><Item Value="0112" Name="Cut Flower and Flower Seed Growing"
+            ><Item Value="011201" Name="Display Foliage Growing"/></Item></Item></Item></Items>]]></assert-xml>
+      </result>       
+   </test-case>
+   
+   <test-case name="su-absorbing-203">
+      <description>Absorbing function - (Saxon incorrect type checking - Saxon bug 3325)</description>
+      <created by="Michael Kay after Martin Honnen" on="2017-06-29"/>
+      <environment>
+         <source file="su-absorbing-202.xml" role="." streaming="true"/>
+      </environment>
+      <test>
+         <stylesheet file="su-absorbing-203.xsl"/>
+      </test>
+      <result>
+         <assert-xml><![CDATA[<Items Title="Title" Icon="Icon" Description="Description"><Item Value="01" Name="Agriculture"
+            ><Item Value="011" Name="Horticulture and Fruit Growing"><Item Value="0111" Name="Plant Nurseries"
+            ><Item Value="011101" Name="Bulb Propagating"/></Item><Item Value="0112" Name="Cut Flower and Flower Seed Growing"
+            ><Item Value="011201" Name="Display Foliage Growing"/></Item></Item></Item></Items>]]></assert-xml>
+      </result>       
+   </test-case>
+   
    <test-case name="su-absorbing-901">
       <description>Invalid absorbing function - not grounded</description>
       <created by="Michael Kay" on="2016-06-27"/>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/strm/su-absorbing/su-absorbing-202.xml	Mon Jul 03 10:06:18 2017 +0100
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Items Title="Title" Icon="Icon" Description="Description">
+    <Item Value="01" Name="Agriculture"/>
+    <Item Value="011" Name="Horticulture and Fruit Growing"/>
+    <Item Value="0111" Name="Plant Nurseries"/>
+    <Item Value="011101" Name="Bulb Propagating"/>
+    <Item Value="0112" Name="Cut Flower and Flower Seed Growing"/>
+    <Item Value="011201" Name="Display Foliage Growing"/>
+</Items>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/strm/su-absorbing/su-absorbing-202.xsl	Mon Jul 03 10:06:18 2017 +0100
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
+    xmlns:xs="http://www.w3.org/2001/XMLSchema" 
+    xmlns:math="http://www.w3.org/2005/xpath-functions/math" 
+    xmlns:mf="http://example.com/mf" 
+    exclude-result-prefixes="xs math mf" 
+    version="3.0">
+    
+    <xsl:param name="STREAMABLE" static="yes" as="xs:boolean" select="true()"/>
+    
+    <xsl:mode _streamable="{$STREAMABLE}" on-no-match="shallow-copy"/>
+    
+    <xsl:output indent="yes"/>
+    
+    <xsl:function name="mf:group" _streamability="{if ($STREAMABLE) then 'absorbing' else 'unclassified'}">
+        <xsl:param name="items" as="element(Item)*"/>
+        <xsl:param name="level" as="xs:integer"/>
+        <xsl:for-each-group select="$items" group-starting-with="Item[string-length(@Value) eq $level]">
+            <xsl:choose>
+                <xsl:when test="self::Item[string-length(@Value) eq $level]">
+                    <xsl:copy>
+                        <xsl:copy-of select="@*"/>
+                        <xsl:sequence select="mf:group(tail(current-group()), $level + 1)"/>
+                    </xsl:copy>
+                </xsl:when>
+                <xsl:otherwise>
+                    <xsl:apply-templates select="mf:group(current-group(), $level + 1)"/>
+                </xsl:otherwise>
+            </xsl:choose>
+        </xsl:for-each-group>
+    </xsl:function>
+    
+    <xsl:template match="Items">
+        <xsl:copy>
+            <xsl:copy-of select="@*"/>
+            <xsl:sequence select="mf:group(Item, 2)"/>
+        </xsl:copy>
+    </xsl:template>
+    
+</xsl:stylesheet>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/strm/su-absorbing/su-absorbing-203.xsl	Mon Jul 03 10:06:18 2017 +0100
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
+    xmlns:xs="http://www.w3.org/2001/XMLSchema" 
+    xmlns:math="http://www.w3.org/2005/xpath-functions/math" 
+    xmlns:mf="http://example.com/mf" 
+    exclude-result-prefixes="xs math mf" 
+    version="3.0">
+    
+    <xsl:param name="STREAMABLE" static="yes" as="xs:boolean" select="true()"/>
+    
+    <xsl:mode _streamable="{$STREAMABLE}" on-no-match="shallow-copy"/>
+    
+    <xsl:output indent="yes"/>
+    
+    <!-- differs from su-absorbing-202 by declaring the required type of the result -->
+    
+    <xsl:function name="mf:group" as="element(Item)*" _streamability="{if ($STREAMABLE) then 'absorbing' else 'unclassified'}">
+        <xsl:param name="items" as="element(Item)*"/>
+        <xsl:param name="level" as="xs:integer"/>
+        <xsl:for-each-group select="$items" group-starting-with="Item[string-length(@Value) eq $level]">
+            <xsl:choose>
+                <xsl:when test="self::Item[string-length(@Value) eq $level]">
+                    <xsl:copy>
+                        <xsl:copy-of select="@*"/>
+                        <xsl:sequence select="mf:group(tail(current-group()), $level + 1)"/>
+                    </xsl:copy>
+                </xsl:when>
+                <xsl:otherwise>
+                    <xsl:apply-templates select="mf:group(current-group(), $level + 1)"/>
+                </xsl:otherwise>
+            </xsl:choose>
+        </xsl:for-each-group>
+    </xsl:function>
+    
+    <xsl:template match="Items">
+        <xsl:copy>
+            <xsl:copy-of select="@*"/>
+            <xsl:sequence select="mf:group(Item, 2)"/>
+        </xsl:copy>
+    </xsl:template>
+    
+</xsl:stylesheet>
\ No newline at end of file