Tests for xsl:stream within a function
authorMichael Kay <mike@saxonica.com>
Thu, 09 Jul 2015 11:20:33 +0100
changeset 1012 6ba26e572cb6
parent 1011 9f4cd1a0f8c2
child 1013 3a7b004c99d4
Tests for xsl:stream within a function
tests/insn/stream/_stream-test-set.xml
tests/insn/stream/stream-500.xsl
tests/insn/stream/stream-B.xsl
--- a/tests/insn/stream/_stream-test-set.xml	Thu Jul 09 11:19:59 2015 +0100
+++ b/tests/insn/stream/_stream-test-set.xml	Thu Jul 09 11:20:33 2015 +0100
@@ -276,6 +276,42 @@
       </result>
    </test-case>
    
+   <test-case name="stream-107">
+      <description>Test xsl:stream called within a function</description>
+      <created by="Michael Kay" on="2015-07-09"/>
+      <environment ref="stream-B"/>
+      <test>
+         <initial-template name="s-107"/>
+      </test>
+      <result>
+         <assert>/out = '9.06'</assert>
+      </result>
+   </test-case>
+   
+   <test-case name="stream-108">
+      <description>Test xsl:stream called with early termination</description>
+      <created by="Michael Kay" on="2015-07-09"/>
+      <environment ref="stream-B"/>
+      <test>
+         <initial-template name="s-108"/>
+      </test>
+      <result>
+         <assert>/out = 'true'</assert>
+      </result>
+   </test-case>
+   
+   <test-case name="stream-109">
+      <description>Test xsl:stream called within a function calling a constructor function</description>
+      <created by="Michael Kay" on="2015-07-09"/>
+      <environment ref="stream-B"/>
+      <test>
+         <initial-template name="s-109"/>
+      </test>
+      <result>
+         <assert>/out = '9.06'</assert>
+      </result>
+   </test-case>
+   
    <test-case name="stream-500">
       <description>Test xsl:stream instruction. From a Saxon 9.6 bug report (bug 2389).</description>
       <created by="Michael Kay" on="2015-06-05"/>
@@ -284,7 +320,12 @@
          <initial-template name="main"/>
       </test>
       <result>
-         <assert>false()</assert><!-- expected results TBA -->
+         <assert-xml><![CDATA[<root xmlns="urn:gba:sqg"
+      xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
+      xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"><body><cases module="17/7" pseud_procedure="17/5_17/7"
+      ><case><patient twodigitik="10"><pseudonym V="1234567890" alg="0"/></patient><test id="1"/></case
+	  ><case><patient twodigitik="10"><pseudonym V="0987654321" alg="0"/></patient><test id="2"/></case
+	  ></cases></body></root>]]></assert-xml>
       </result>
    </test-case>
 
--- a/tests/insn/stream/stream-500.xsl	Thu Jul 09 11:19:59 2015 +0100
+++ b/tests/insn/stream/stream-500.xsl	Thu Jul 09 11:20:33 2015 +0100
@@ -3,7 +3,7 @@
 	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"
 	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns0="urn:gba:sqg"
 	exclude-result-prefixes="xs xsi ns0">
-	<xsl:output method="xml" encoding="UTF-8" indent="yes" />
+	<xsl:output method="xml" encoding="UTF-8" indent="no" />
 
 	<xsl:param name="doc4" select="'stream-500.xml'"/>
 
@@ -18,7 +18,7 @@
                             <xsl:variable name="lfd" select="@lfdnr" />
                             <case>
                                 <xsl:stream href="{$doc4}">
-                                    <xsl:copy-of select="ns0:root/ns0:body/ns0:case[(@lfdnr) = ($lfd)]/ns0:patient" />
+                                    <xsl:copy-of select="ns0:root/ns0:body/ns0:case[(@lfdnr) = ($lfd)]/ns0:patient" copy-namespaces="false"/>
                                     <test id="{$lfd}" />
                                 </xsl:stream>
                             </case>
--- a/tests/insn/stream/stream-B.xsl	Thu Jul 09 11:19:59 2015 +0100
+++ b/tests/insn/stream/stream-B.xsl	Thu Jul 09 11:20:33 2015 +0100
@@ -2,7 +2,8 @@
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:map="http://www.w3.org/2005/xpath-functions/map"
     xmlns:xs="http://www.w3.org/2001/XMLSchema"
-    exclude-result-prefixes="map xs">
+    xmlns:f="http://local-functions.org/"
+    exclude-result-prefixes="map xs f">
     
     <xsl:variable name="RUN" select="true()" static="yes"/>
     
@@ -68,6 +69,44 @@
       </out>
     </xsl:template>
     
+    <!-- xsl:stream called within a function -->
+    
+    <xsl:template name="s-107" use-when="$RUN">
+      <out>
+        <xsl:value-of select="round(avg(f:read-stream('books.xml')), 2)"/>
+      </out>
+    </xsl:template>
+    
+    <xsl:function name="f:read-stream" as="xs:decimal*">
+      <xsl:param name="uri" as="xs:string"/>
+      <xsl:stream href="{$uri}">
+        <xsl:sequence select="//PRICE/data(.)"/>
+      </xsl:stream>
+    </xsl:function>
+    
+    <!-- xsl:stream called within a function with early termination -->
+    
+    <xsl:template name="s-108" use-when="$RUN">
+      <out>
+        <xsl:value-of select="exists(f:read-stream('books.xml'))"/>
+      </out>
+    </xsl:template>
+    
+    <!-- xsl:stream called within a function using a constructor function -->
+    
+    <xsl:template name="s-109" use-when="$RUN">
+      <out>
+        <xsl:value-of select="round(avg(f:read-stream-decimal('books.xml')), 2)"/>
+      </out>
+    </xsl:template>
+    
+    <xsl:function name="f:read-stream-decimal" as="xs:decimal*">
+      <xsl:param name="uri" as="xs:string"/>
+      <xsl:stream href="{$uri}">
+        <xsl:sequence select="//PRICE/xs:decimal(.)"/>
+      </xsl:stream>
+    </xsl:function>    
+