New test for accumulator-after
authorMichael Kay <mike@saxonica.com>
Mon, 11 Jan 2016 11:28:21 +0000
changeset 1199 69cf9726a11f
parent 1198 aacf3d6d8681
child 1200 6da4ce1bab22
New test for accumulator-after
tests/decl/accumulator/_accumulator-test-set.xml
tests/decl/accumulator/accumulator-053.xml
tests/decl/accumulator/accumulator-053.xsl
--- a/tests/decl/accumulator/_accumulator-test-set.xml	Mon Jan 11 11:27:29 2016 +0000
+++ b/tests/decl/accumulator/_accumulator-test-set.xml	Mon Jan 11 11:28:21 2016 +0000
@@ -1071,5 +1071,28 @@
          <assert-xml><![CDATA[<root><end value="57"/></root>]]></assert-xml>
       </result>
    </test-case>
+   
+   <test-case name="accumulator-053">
+      <description>Check that accumulator-after is the value AFTER applying the post-descent rule (Saxon bug 2478)</description>
+      <created by="Michael Kay, after Martin Honnen" on="2016-01-02"/>
+      <environment>
+         <source role="." file="accumulator-053.xml" streaming="true"/>
+      </environment>
+      <test>
+         <stylesheet file="accumulator-053.xsl"/>
+      </test>
+      <result>
+         <assert-xml><![CDATA[<root><start state=""
+            /><start name="A" state="(A"
+            /><start name="B" state="(A (B"
+            /><start name="C" state="(A (B (C"
+            /><end name="C" state="(A (B (C C)"
+            /><start name="D" state="(A (B (C C) (D"
+            /><end name="D" state="(A (B (C C) (D D)"
+            /><end name="B" state="(A (B (C C) (D D) B)"
+            /><end name="A" state="(A (B (C C) (D D) B) A)"
+            /><end state="(A (B (C C) (D D) B) A)"/></root>]]></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/decl/accumulator/accumulator-053.xml	Mon Jan 11 11:28:21 2016 +0000
@@ -0,0 +1,16 @@
+<products>
+    <product type="apple"/>
+    <product type="banana"/>
+    <product type="cherry"/>
+    <product type="damson"/>
+    <product type="elderberry"/>
+    <product type="greengage"/>
+    <product type="plum"/>
+    <product type="quince"/>
+    <product type="raspberry"/>
+    <product type="strawberry"/>
+    <product type="tangerine"/>
+    <product type="apple"/>
+    <product type="banana"/>
+    <product type="cherry"/>
+</products>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/decl/accumulator/accumulator-053.xsl	Mon Jan 11 11:28:21 2016 +0000
@@ -0,0 +1,29 @@
+<?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:map="http://www.w3.org/2005/xpath-functions/map"
+  exclude-result-prefixes="xs map"
+  version="3.0">
+  
+  <xsl:mode streamable="yes"/>
+  <xsl:global-context-item use-accumulators="type-count"/>
+  
+  <xsl:output method="text"/>
+  
+  <xsl:accumulator name="type-count" as="map(xs:string, xs:integer)" initial-value="map{}" streamable="yes">
+    <xsl:accumulator-rule match="product">
+      <xsl:sequence select="if (map:contains($value, @type))
+        then map:put($value, string(@type), $value(@type) + 1)
+        else map:put($value, string(@type), 1)"/>
+    </xsl:accumulator-rule>
+  </xsl:accumulator>
+  
+  <xsl:template match="/">
+    <xsl:for-each select="*/*">
+      <xsl:message select="node-name(.)"/>
+    </xsl:for-each>
+    <xsl:value-of select="serialize(accumulator-after('type-count'), map{ 'method' : 'adaptive'})"/>
+  </xsl:template>
+  
+</xsl:stylesheet>
\ No newline at end of file