Add accumulator test using a sequence constructor in accumulator rule
authorMichael Kay <mike@saxonica.com>
Sat, 02 Aug 2014 16:04:51 +0100
changeset 587 06fbe545f76b
parent 586 fe0d05b1a577
child 588 abe02b4a9456
Add accumulator test using a sequence constructor in accumulator rule
tests/decl/accumulator/_accumulator-test-set.xml
tests/decl/accumulator/accumulator-036.xsl
--- a/tests/decl/accumulator/_accumulator-test-set.xml	Fri Aug 01 22:24:15 2014 +0100
+++ b/tests/decl/accumulator/_accumulator-test-set.xml	Sat Aug 02 16:04:51 2014 +0100
@@ -301,7 +301,7 @@
          <assert>/Total-Cost = '91'</assert>
       </result>
    </test-case>
-
+   
    <test-case name="accumulator-016">
       <description>
       	Multiple accumulators used in parallel; uses @applies-to. Non-streaming.
@@ -638,6 +638,24 @@
          <assert-xml><![CDATA[<figures><p>Figure 2: a diagram</p><p>Figure 4: another diagram</p><p>Figure 2: a third diagram</p><p>Figure 4: a fourth diagram</p></figures>]]></assert-xml>
       </result>
    </test-case>
+   
+   <test-case name="accumulator-036s">
+      <description>Sequence constructor in accumulator rule</description>
+      <keywords>xsl:mode streamable post-descent non-streamable</keywords>
+      <created by="Michael Kay" on="2014-08-02"/>
+      <environment ref="accumulator-015s"/>
+      <dependencies>
+         <feature value="streaming"/>
+      </dependencies>
+      <test>
+         <stylesheet file="accumulator-036.xsl"/>
+      </test>
+      <result>
+         <assert>/Total-Cost = '91'</assert><!-- needs revision -->
+      </result>
+   </test-case>
+
+
 
 
 </test-set>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/decl/accumulator/accumulator-036.xsl	Sat Aug 02 16:04:51 2014 +0100
@@ -0,0 +1,27 @@
+<?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:f="function"
+               exclude-result-prefixes="#all"
+               version="3.0">
+
+   <xsl:output method="xml" />
+
+   <xsl:mode streamable="yes" />
+
+   <xsl:accumulator name="item-cost" streamable="yes" 
+       as="xs:integer" 
+       initial-value="0">
+       <xsl:accumulator-rule match="cost/text()">
+         <xsl:sequence select="$value + xs:integer(.)"/>
+       </xsl:accumulator-rule>  
+   </xsl:accumulator>
+
+   <xsl:template match="purchase-order">
+       <Total-Cost>
+           <items><xsl:value-of select="count(//item)"/></items>
+           <cost><xsl:value-of select="accumulator-after('item-cost')" /></cost>
+       </Total-Cost>
+   </xsl:template>
+
+</xsl:stylesheet>
\ No newline at end of file