Streaming "for" expressions (grounded+consuming)
authorMichael Kay <mike@saxonica.com>
Fri, 27 Mar 2015 16:19:34 +0000
changeset 873 da2b52d32ee7
parent 867 7956813ae249
child 874 b68990df6405
Streaming "for" expressions (grounded+consuming)
catalog.xml
tests/strm/sx-ForExpr/_sx-ForExpr-test-set.xml
tests/strm/sx-ForExpr/sx-for-A.xsl
--- a/catalog.xml	Fri Mar 27 15:25:44 2015 +0000
+++ b/catalog.xml	Fri Mar 27 16:19:34 2015 +0000
@@ -235,6 +235,7 @@
       
       <test-set name="sx-ArithmeticExpr" file="tests/strm/sx-ArithmeticExpr/_sx-ArithmeticExpr-test-set.xml"/>
       <test-set name="sx-CommaExpr" file="tests/strm/sx-CommaExpr/_sx-CommaExpr-test-set.xml"/>
+      <test-set name="sx-ForExpr" file="tests/strm/sx-ForExpr/_sx-ForExpr-test-set.xml"/>
       <test-set name="sx-ExceptExpr" file="tests/strm/sx-ExceptExpr/_sx-ExceptExpr-test-set.xml"/>
       <test-set name="sx-FunctionCall" file="tests/strm/sx-FunctionCall/_sx-FunctionCall-test-set.xml"/>
       <test-set name="sx-GeneralComp-eq" file="tests/strm/sx-GeneralComp-eq/_sx-GeneralComp-eq-test-set.xml"/>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/strm/sx-ForExpr/_sx-ForExpr-test-set.xml	Fri Mar 27 16:19:34 2015 +0000
@@ -0,0 +1,76 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<test-set xmlns="http://www.w3.org/2012/10/xslt-test-catalog" xmlns:xs="http://www.w3.org/2001/XMLSchema" name="sx-ForExpr">
+   <description>for expressions  with streaming</description>
+   
+   <environment name="sx-for-A">
+     <stylesheet file="sx-for-A.xsl"/>
+   </environment>
+   
+   <dependencies>
+      <spec value="XSLT30+"/>
+      <feature value="streaming"/>
+   </dependencies>
+   
+   <test-case name="sx-for-001">
+      <description>Streaming for expression - "in" expression is grounded and consuming</description>
+      <created by="Michael Kay" on="2015-03-27"/>
+      <environment ref="sx-for-A"/>
+      <test>
+         <initial-template name="r-001"/>
+      </test>
+      <result>
+        <assert-xml><![CDATA[<out>26.1 25 22.8 24.9 57 24.7</out>]]></assert-xml>
+      </result>
+   </test-case>
+   
+   <test-case name="sx-for-002">
+      <description>Streaming for expression - "in" expression is grounded and consuming</description>
+      <created by="Michael Kay" on="2015-03-27"/>
+      <environment ref="sx-for-A"/>
+      <test>
+         <initial-template name="r-002"/>
+      </test>
+      <result>
+        <assert-xml><![CDATA[<out>26.1 25 22.8 24.9 57 24.7</out>]]></assert-xml>
+      </result>
+   </test-case>
+   
+   <test-case name="sx-for-003">
+      <description>Streaming for expression - "in" expression is grounded and consuming</description>
+      <created by="Michael Kay" on="2015-03-27"/>
+      <environment ref="sx-for-A"/>
+      <test>
+         <initial-template name="r-003"/>
+      </test>
+      <result>
+        <assert-xml><![CDATA[<out>26.1 25 22.8 24.9 57 24.7</out>]]></assert-xml>
+      </result>
+   </test-case>
+   
+   <test-case name="sx-for-004">
+      <description>Streaming for expression - "in" expression is grounded and consuming</description>
+      <created by="Michael Kay" on="2015-03-27"/>
+      <environment ref="sx-for-A"/>
+      <test>
+         <initial-template name="r-004"/>
+      </test>
+      <result>
+        <assert-xml><![CDATA[<out>26.1 25 22.8 24.9 57 24.7</out>]]></assert-xml>
+      </result>
+   </test-case>
+   
+   <test-case name="sx-for-005">
+      <description>Streaming for expression - "in" expression is grounded and consuming</description>
+      <created by="Michael Kay" on="2015-03-27"/>
+      <environment ref="sx-for-A"/>
+      <test>
+         <initial-template name="r-005"/>
+      </test>
+      <result>
+        <assert-xml><![CDATA[<out>Q{}OWNER Q{}CAT Q{}UNIT Q{}CAT Q{}UNIT Q{}CAT Q{}UNIT Q{}CAT Q{}UNIT Q{}CAT Q{}UNIT Q{}CAT Q{}UNIT</out>]]></assert-xml>
+      </result>
+   </test-case>
+   
+   
+
+</test-set>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/strm/sx-ForExpr/sx-for-A.xsl	Fri Mar 27 16:19:34 2015 +0000
@@ -0,0 +1,58 @@
+<xsl:stylesheet version="3.0" 
+    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">
+    
+    <xsl:variable name="RUN" select="true()" static="yes"/>
+    <xsl:strip-space elements="*"/>
+
+    <!-- "For" expression with consuming and grounded "in" operand.
+        Use two references to the range variable to avoid inlining. -->
+    
+    <xsl:template name="r-001" use-when="$RUN">
+      <xsl:stream href="../docs/books.xml">
+        <out>
+          <xsl:value-of select="for $x in /BOOKLIST/BOOKS/ITEM/DIMENSIONS/string() return sum(tokenize($x, ' ')!xs:decimal(.)) + string-length($x)"/>
+        </out>
+      </xsl:stream>
+    </xsl:template>
+    
+    <xsl:template name="r-002" use-when="$RUN">
+      <xsl:stream href="../docs/books.xml">
+        <out>
+          <xsl:value-of select="for $x in /BOOKLIST/BOOKS/ITEM/DIMENSIONS/data() return sum(tokenize($x, ' ')!xs:decimal(.)) + string-length($x)"/>
+        </out>
+      </xsl:stream>
+    </xsl:template>
+    
+    <xsl:template name="r-003" use-when="$RUN">
+      <xsl:stream href="../docs/books.xml">
+        <out>
+          <xsl:value-of select="for $x in /BOOKLIST/BOOKS/ITEM/DIMENSIONS/copy-of() return sum(tokenize($x, ' ')!xs:decimal(.)) + string-length($x)"/>
+        </out>
+      </xsl:stream>
+    </xsl:template>
+    
+    <xsl:template name="r-004" use-when="$RUN">
+      <xsl:stream href="../docs/books.xml">
+        <out>
+          <xsl:value-of select="
+            for $x in /BOOKLIST/BOOKS/ITEM/DIMENSIONS/snapshot() 
+            return sum(tokenize($x, ' ')!number()) + count($x/ancestor::node())"/>
+        </out>
+      </xsl:stream>
+    </xsl:template>
+    
+    <xsl:template name="r-005" use-when="$RUN">
+      <xsl:stream href="../docs/books.xml">
+        <out>
+          <xsl:value-of select="
+            for $x in /BOOKLIST/BOOKS/ITEM/DIMENSIONS/ancestor-or-self::*/@*/node-name() 
+            return ('Q{'||namespace-uri-from-QName($x)||'}'||local-name-from-QName($x))"/>
+        </out>
+      </xsl:stream>
+    </xsl:template>
+         
+    
+</xsl:stylesheet>
\ No newline at end of file