Merge with default keywords
authorabraaksm
Wed, 23 Jul 2014 17:02:10 +0200
branchkeywords
changeset 522 30baf7c413bb
parent 521 7ec2c6d22adb (current diff)
parent 495 ed6d3af522b5 (diff)
child 523 87995fd77617
Merge with default
admin/catalog-schema.xsd
tests/decl/accumulator/_accumulator-test-set.xml
tests/decl/accumulator/accumulator-002.xsl
tests/decl/accumulator/accumulator-004.xsl
tests/decl/accumulator/accumulator-006.xsl
tests/decl/accumulator/accumulator-008.xsl
tests/decl/accumulator/accumulator-011.xsl
tests/decl/accumulator/accumulator-013.xsl
tests/strm/sf-avg/_sf-avg-test-set.xml
tests/strm/sf-boolean/_sf-boolean-test-set.xml
--- a/admin/catalog-schema.xsd	Wed Jul 23 16:35:29 2014 +0200
+++ b/admin/catalog-schema.xsd	Wed Jul 23 17:02:10 2014 +0200
@@ -1231,12 +1231,13 @@
                     </xs:annotation>
                 </xs:element>
                 <xs:element ref="param" minOccurs="0" maxOccurs="unbounded"/>
-                <xs:element ref="initial-template" minOccurs="0"/>
-                <xs:element ref="initial-mode" minOccurs="0"/>
+                <xs:element ref="initial-template" minOccurs="0" />
+                <xs:element ref="initial-mode" minOccurs="0" />
+                <xs:element ref="output" minOccurs="0" />
             </xs:sequence>
-        </xs:complexType>
+        </xs:complexType>        
     </xs:element>
-
+    
     <xs:element name="initial-template">
         <xs:annotation>
             <xs:documentation>
@@ -1256,10 +1257,24 @@
             </xs:documentation>
         </xs:annotation>
         <xs:complexType>
-            <xs:attribute name="name" type="xs:QName"/>
+            <xs:attribute name="name" type="xs:QName" />
         </xs:complexType>
     </xs:element>
-
+    
+    <xs:element name="output">
+        <xs:annotation>
+            <xs:documentation>
+                <p>Provides a base output URI for the transformation. The processor may (optionally) use this as the
+                location to which serialized output for the principal result tree is written. The location should be
+                given as a relative URI, and should be within a subdirectory of the directory that contains the test 
+                set XML file.</p>
+            </xs:documentation>         
+        </xs:annotation>
+        <xs:complexType>
+            <xs:attribute name="file" type="xs:anyURI" />
+        </xs:complexType>
+    </xs:element>    
+    
     <xs:element name="created">
         <xs:annotation>
             <xs:documentation>
--- a/catalog.xml	Wed Jul 23 16:35:29 2014 +0200
+++ b/catalog.xml	Wed Jul 23 17:02:10 2014 +0200
@@ -62,6 +62,7 @@
       <test-set name="collection" file="tests/fn/collection/_collection-test-set.xml"/>
       <test-set name="core-function" file="tests/fn/core-function/_core-function-test-set.xml"/>
       <test-set name="copy-of" file="tests/fn/copy-of/_copy-of-test-set.xml"/>
+      <test-set name="current-output-uri" file="tests/fn/current-output-uri/_current-output-uri-test-set.xml"/>      
       <test-set name="deep-equal" file="tests/fn/deep-equal/_deep-equal-test-set.xml"/>
       <test-set name="document" file="tests/fn/document/_document-test-set.xml"/>         
       <test-set name="extension-functions" file="tests/fn/extension-functions/_extension-functions-test-set.xml"/>
@@ -70,16 +71,19 @@
       <test-set name="format-number" file="tests/fn/format-number/_format-number-test-set.xml"/>
       <test-set name="function-available" file="tests/fn/function-available/_function-available-test-set.xml"/>         
       <test-set name="id" file="tests/fn/id/_id-test-set.xml"/>
+      <test-set name="json-to-xml" file="tests/fn/json-to-xml/_json-to-xml-test-set.xml"/>
       <test-set name="key" file="tests/fn/key/_key-test-set.xml"/>
       <test-set name="normalize-unicode" file="tests/fn/normalize-unicode/_normalize-unicode-test-set.xml"/>         
       <test-set name="position" file="tests/fn/position/_position-test-set.xml"/>
       <test-set name="resolve-uri" file="tests/fn/resolve-uri/_resolve-uri-test-set.xml"/>         
       <test-set name="root" file="tests/fn/root/_root-test-set.xml"/>
       <test-set name="snapshot" file="tests/fn/snapshot/_snapshot-test-set.xml"/>
+      <test-set name="stream-available" file="tests/fn/stream-available/_stream-available-test-set.xml"/>
       <test-set name="system-property" file="tests/fn/system-property/_system-property-test-set.xml"/>
       <test-set name="type-available" file="tests/fn/type-available/_type-available-test-set.xml"/>
       <test-set name="unparsed-text" file="tests/fn/unparsed-text/_unparsed-text-test-set.xml"/>         
       <test-set name="unparsed-text-lines" file="tests/fn/unparsed-text-lines/_unparsed-text-lines-test-set.xml"/>
+      <test-set name="xml-to-json" file="tests/fn/xml-to-json/_xml-to-json-test-set.xml"/>
       
       <!-- Instructions -->
       
--- a/tests/decl/accumulator/_accumulator-test-set.xml	Wed Jul 23 16:35:29 2014 +0200
+++ b/tests/decl/accumulator/_accumulator-test-set.xml	Wed Jul 23 17:02:10 2014 +0200
@@ -4,9 +4,7 @@
    <environment name="accumulator-001">
       <source role="." file="accumulator-001.xml"/>
    </environment>
-   <environment name="accumulator-001s">
-      <source role="." file="accumulator-001.xml" streaming="true"/>
-   </environment>
+   
    <environment name="accumulator-002">
       <source role="." file="accumulator-002.xml"/>
    </environment>
@@ -39,22 +37,26 @@
       <environment ref="accumulator-001"/>
       <test>
          <stylesheet file="accumulator-001.xsl"/>
+         <param name="streamable" static="yes" select="'no'"/>
       </test>
       <result>
          <assert-xml><![CDATA[<figures><p>Figure 1: a diagram</p><p>Figure 2: another diagram</p><p>Figure 1: a third diagram</p><p>Figure 2: a fourth diagram</p></figures>]]></assert-xml>
       </result>
    </test-case>
 
-   <test-case name="accumulator-002">
+   <test-case name="accumulator-001s">
       <description>Basic test of accumulator functions - streaming</description>
       <keywords>xsl:mode on-no-match-attribute shallow-skip fn:accumulator-before ElementTest streamable</keywords>
       <created by="Michael Kay" on="2012-11-07"/>
-      <environment ref="accumulator-001s"/>
+      <environment>
+         <source role="." file="accumulator-001.xml" streaming="true"/>
+   	  </environment>
       <dependencies>
          <feature value="streaming"/>
       </dependencies>
       <test>
-         <stylesheet file="accumulator-002.xsl"/>
+         <stylesheet file="accumulator-001.xsl"/>
+         <param name="streamable" static="yes" select="'yes'"/>
       </test>
       <result>
          <assert-xml><![CDATA[<figures><p>Figure 1: a diagram</p><p>Figure 2: another diagram</p><p>Figure 1: a third diagram</p><p>Figure 2: a fourth diagram</p></figures>]]></assert-xml>
@@ -68,6 +70,7 @@
       <environment ref="accumulator-002"/>
       <test>
          <stylesheet file="accumulator-003.xsl"/>
+         <param name="streamable" static="yes" select="'no'"/>
       </test>
       <result>
          <assert-xml><![CDATA[<figures><pix><p>Figure 1 start</p><p>Figure 1 end</p></pix
@@ -77,7 +80,7 @@
       </result>
    </test-case>
 
-   <test-case name="accumulator-004">
+   <test-case name="accumulator-003s">
       <description>Pre-descent accumulator functions called before and after - streaming</description>
       <keywords>xsl:mode on-no-match-attribute shallow-skip fn:accumulator-before streamable</keywords>
       <created by="Michael Kay" on="2012-11-07"/>
@@ -86,7 +89,8 @@
          <feature value="streaming"/>
       </dependencies>
       <test>
-         <stylesheet file="accumulator-004.xsl"/>
+         <stylesheet file="accumulator-003.xsl"/>
+         <param name="streamable" static="yes" select="'yes'"/>
       </test>
       <result>
          <assert-xml><![CDATA[<figures><pix><p>Figure 1 start</p><p>Figure 1 end</p></pix
@@ -103,6 +107,7 @@
       <environment ref="accumulator-002"/>
       <test>
          <stylesheet file="accumulator-005.xsl"/>
+         <param name="streamable" static="yes" select="'no'"/>
       </test>
       <result>
          <assert-xml><![CDATA[<figures><pix><p>Figure 1 start</p><p>Figure 1.5 end</p></pix
@@ -112,7 +117,7 @@
       </result>
    </test-case>
 
-   <test-case name="accumulator-006">
+   <test-case name="accumulator-005s">
       <description>Pre-descent and post-descent accumulator functions - streaming</description>
       <keywords>xsl:mode on-no-match-attribute shallow-skip fn:accumulator-before fn:accumulator-after streamable</keywords>
       <created by="Michael Kay" on="2012-11-07"/>
@@ -121,7 +126,8 @@
          <feature value="streaming"/>
       </dependencies>
       <test>
-         <stylesheet file="accumulator-006.xsl"/>
+         <stylesheet file="accumulator-005.xsl"/>
+         <param name="streamable" static="yes" select="'yes'"/>
       </test>
       <result>
          <assert-xml><![CDATA[<figures><pix><p>Figure 1 start</p><p>Figure 1.5 end</p></pix
@@ -132,44 +138,49 @@
    </test-case>
 
    <test-case name="accumulator-007">
-      <description>Multiple accumulators used in parallel</description>
-      <keywords>xsl:mode on-no-match-attribute shallow-skip multiple-accumulators fn:accumulator-after</keywords>
+      <description>Multiple accumulators used in parallel; uses @applies-to</description>
+      <keywords>xsl:mode on-no-match-attribute shallow-skip multiple-accumulators fn:accumulator-after applies-to-attribute</keywords>
       <created by="Michael Kay" on="2012-11-07"/>
       <environment ref="accumulator-004"/>
       <test>
          <stylesheet file="accumulator-007.xsl"/>
+         <param name="streamable" static="yes" select="'no'"/>
       </test>
       <result>
          <assert-xml><![CDATA[<result min="-16" max="182" sum="277.43" count="16" avg="17.34"/>]]></assert-xml>
       </result>
    </test-case>
 
-   <test-case name="accumulator-008">
-      <description>Multiple accumulators used in parallel - with streaming</description>
-      <keywords>xsl:mode on-no-match-attribute shallow-skip multiple-accumulators fn:accumulator-after streamable</keywords>
+   <test-case name="accumulator-007s">
+      <description>Multiple accumulators used in parallel - with streaming; uses @applies-to</description>
+      <keywords>xsl:mode on-no-match-attribute shallow-skip multiple-accumulators fn:accumulator-after streamable applies-to-attribute</keywords>
       <created by="Michael Kay" on="2012-11-07"/>
       <environment ref="accumulator-004s"/>
       <dependencies>
          <feature value="streaming"/>
       </dependencies>
       <test>
-         <stylesheet file="accumulator-008.xsl"/>
+         <stylesheet file="accumulator-007.xsl"/>
+         <param name="streamable" static="yes" select="'yes'"/>
       </test>
       <result>
          <assert-xml><![CDATA[<result min="-16" max="182" sum="277.43" count="16" avg="17.34"/>]]></assert-xml>
       </result>
    </test-case>
 
-   <test-case name="accumulator-009">
+   <test-case name="accumulator-009s">
       <description>Error: post-descent accumulator function used in a pre-descent instruction</description>
-      <keywords>xsl:mode on-no-match-attribute deep-skip multiple-accumulators fn:accumulator-after streamable</keywords>
+      <keywords>xsl:mode on-no-match-attribute deep-skip multiple-accumulators fn:accumulator-after streamable XTDE3420</keywords>
       <created by="Michael Kay" on="2012-11-07"/>
       <environment ref="accumulator-004s"/>
+      <dependencies>
+         <feature value="streaming"/>
+      </dependencies>
       <test>
          <stylesheet file="accumulator-009.xsl"/>
       </test>
       <result>
-         <error code="XXXX9999"/>
+         <error code="XTDE3420"/>
       </result>
    </test-case>
 
@@ -181,6 +192,7 @@
       <dependencies/>
       <test>
          <stylesheet file="accumulator-010.xsl"/>
+         <param name="streamable" static="yes" select="'no'"/>
       </test>
       <result>
          <assert-xml><![CDATA[<doc><span>1</span><span>Intro</span><p>In the beginning</p
@@ -193,7 +205,7 @@
       </result>
    </test-case>
 
-   <test-case name="accumulator-011">
+   <test-case name="accumulator-010s">
       <description>Hierarchic section numbers: uses accumulator rules with phase=end. Once more with streaming.</description>
       <keywords>xsl:mode on-no-match-attribute streamable shallow-copy streamable fn:accumulator-before</keywords>
       <created by="Michael Kay" on="2012-11-07"/>
@@ -202,7 +214,8 @@
          <feature value="streaming"/>
       </dependencies>
       <test>
-         <stylesheet file="accumulator-011.xsl"/>
+         <stylesheet file="accumulator-010.xsl"/>
+         <param name="streamable" static="yes" select="'yes'"/>
       </test>
       <result>
          <assert-xml><![CDATA[<doc><span>1</span><span>Intro</span><p>In the beginning</p
@@ -223,6 +236,7 @@
       <dependencies/>
       <test>
          <stylesheet file="accumulator-012.xsl"/>
+         <param name="streamable" static="yes" select="'no'"/>
       </test>
       <result>
          <assert-xml><![CDATA[<doc><head>Intro</head><p>In the beginning</p><head>Terminology</head
@@ -235,14 +249,17 @@
       </result>
    </test-case>
    
-   <test-case name="accumulator-013">
+   <test-case name="accumulator-012s">
       <description>Accumulator matching text node - streamable</description>
       <keywords>xsl:mode on-no-match-attribute shallow-copy TextTest fn:accumulator-after streamable</keywords>
       <created by="Michael Kay" on="2013-09-07"/>
       <environment ref="accumulator-005s"/>
-      <dependencies/>
+      <dependencies>
+         <feature value="streaming"/>
+      </dependencies>
       <test>
-         <stylesheet file="accumulator-013.xsl"/>
+         <stylesheet file="accumulator-012.xsl"/>
+         <param name="streamable" static="yes" select="'yes'"/>
       </test>
       <result>
          <assert-xml><![CDATA[<doc><head>Intro</head><p>In the beginning</p><head>Terminology</head
@@ -268,16 +285,359 @@
       </result>
    </test-case>
    
-   <test-case name="accumulator-015">
+   <test-case name="accumulator-015s">
       <description>Use post-descent accumulator function</description>
       <keywords>xsl:mode streamable post-descent non-streamable _WRONG:illegal-accumulator-streaming-non-streaming</keywords>
       <created by="Michael Kay" on="2013-12-20"/>
+      <modified by="Michael Kay" on="2014-07-03" change="make streamable, define expected result"/>
       <environment ref="accumulator-015s"/>
+      <dependencies>
+         <feature value="streaming"/>
+      </dependencies>
       <test>
          <stylesheet file="accumulator-015.xsl"/>
       </test>
       <result>
+         <assert>/Total-Cost = '91'</assert>
+      </result>
+   </test-case>
+
+   <test-case name="accumulator-016">
+      <description>
+      	Multiple accumulators used in parallel; uses @applies-to. Non-streaming.
+      	Error: accumulator does not apply to current document.
+      </description>
+      <created by="Michael Kay" on="2014-07-04"/>
+      <environment ref="accumulator-004"/>
+      <test>
+         <stylesheet file="accumulator-007.xsl"/>
+         <param name="applies-to" as="xs:string" select="'bananas'" static="yes"/>
+         <param name="streamable" static="yes" select="'no'"/>
+      </test>
+      <result>
+         <error code="XTDE3361"/>
+      </result>
+   </test-case>
+   
+   <test-case name="accumulator-016s">
+      <description>
+      	Applies-to pattern is not motionless. Error case when streaming.
+      </description>
+      <created by="Michael Kay" on="2014-07-04"/>
+      <environment ref="accumulator-004s"/>
+      <dependencies>
+         <feature value="streaming"/>
+      </dependencies>
+      <test>
+         <stylesheet file="accumulator-007.xsl"/>
+         <param name="applies-to" as="xs:string" select="'transactions[transaction]'" static="yes"/>
+         <param name="streamable" static="yes" select="'yes'"/>
+      </test>
+      <result>
+         <error code="XTSE3430"/>
+      </result>
+   </test-case>
+
+   <test-case name="accumulator-018s">
+      <description>
+      	Multiple accumulators used in parallel; uses @applies-to. Streaming.
+      	Error: accumulator does not apply to current document.
+      </description>
+      <created by="Michael Kay" on="2014-07-04"/>
+      <environment ref="accumulator-004s"/>
+      <dependencies>
+         <feature value="streaming"/>
+      </dependencies>
+      <test>
+         <stylesheet file="accumulator-007.xsl"/>
+         <param name="applies-to" as="xs:string" select="'bananas'" static="yes"/>
+         <param name="streamable" static="yes" select="'yes'"/>
+      </test>
+      <result>
+         <error code="XTDE3361"/>
+      </result>
+   </test-case>
+   
+   <test-case name="accumulator-019s">
+      <description>
+      	Initial-value expression is not motionless. Error case when streaming.
+      	NOTE: focus for initial-value is still an open question.
+      </description>
+      <created by="Michael Kay" on="2014-07-04"/>
+      <environment ref="accumulator-004s"/>
+      <dependencies>
+         <feature value="streaming"/>
+      </dependencies>
+      <test>
+         <stylesheet file="accumulator-007.xsl"/>
+         <param name="initial-count" as="xs:string" select="'//x'" static="yes"/>
+         <param name="streamable" static="yes" select="'yes'"/>
+      </test>
+      <result>
+         <error code="XTSE3430"/>
+      </result>
+   </test-case>
+   
+   <test-case name="accumulator-020">
+      <description>Namespace-qualified accumulator names</description>
+      <created by="Michael Kay" on="2014-07-07"/>
+      <environment ref="accumulator-001"/>
+      <test>
+         <stylesheet file="accumulator-020.xsl"/>
+         <param name="one" static="yes" select="'f:one'"/>
+         <param name="two" static="yes" select="'g:two'"/>
+      </test>
+      <result>
          <assert-xml><![CDATA[<figures><p>Figure 1: a diagram</p><p>Figure 2: another diagram</p><p>Figure 1: a third diagram</p><p>Figure 2: a fourth diagram</p></figures>]]></assert-xml>
       </result>
    </test-case>
+   
+   <test-case name="accumulator-021">
+      <description>Namespace-qualified accumulator names</description>
+      <created by="Michael Kay" on="2014-07-07"/>
+      <environment ref="accumulator-001"/>
+      <test>
+         <stylesheet file="accumulator-020.xsl"/>
+         <param name="one" static="yes" select="'Q{http://one.org/}one'"/>
+         <param name="two" static="yes" select="'Q{http://one.org/}two'"/>
+      </test>
+      <result>
+         <assert-xml><![CDATA[<figures><p>Figure 1: a diagram</p><p>Figure 2: another diagram</p><p>Figure 1: a third diagram</p><p>Figure 2: a fourth diagram</p></figures>]]></assert-xml>
+      </result>
+   </test-case>
+   
+   <test-case name="accumulator-022">
+      <description>Namespace-qualified accumulator names: error, duplicate names</description>
+      <created by="Michael Kay" on="2014-07-07"/>
+      <environment ref="accumulator-001"/>
+      <test>
+         <stylesheet file="accumulator-020.xsl"/>
+         <param name="one" static="yes" select="'f:one'"/>
+         <param name="two" static="yes" select="'f2:one'"/>
+      </test>
+      <result>
+         <error code="XTSE3350"/>
+      </result>
+   </test-case>
+   
+   <test-case name="accumulator-023">
+      <description>Import precedence applied to accumulators</description>
+      <created by="Michael Kay" on="2014-07-07"/>
+      <environment ref="accumulator-001"/>
+      <test>
+         <stylesheet file="accumulator-023.xsl"/>
+      </test>
+      <result>
+         <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-024">
+      <description>An accumulator must have at least one rule</description>
+      <created by="Michael Kay" on="2014-07-07"/>
+      <environment ref="accumulator-001"/>
+      <test>
+         <stylesheet file="accumulator-024.xsl"/>
+      </test>
+      <result>
+         <error code="XTSE0010"/>
+      </result>
+   </test-case>
+   
+   <test-case name="accumulator-025">
+      <description>Initial value is mandatory</description>
+      <created by="Michael Kay" on="2014-07-07"/>
+      <environment ref="accumulator-001"/>
+      <test>
+         <stylesheet file="accumulator-025.xsl"/>
+      </test>
+      <result>
+         <error code="XTSE0010"/>
+      </result>
+   </test-case>
+   
+   <test-case name="accumulator-026">
+      <description>Rules matching attribute nodes are legal but ignored</description>
+      <created by="Michael Kay" on="2014-07-07"/>
+      <environment ref="accumulator-001"/>
+      <test>
+         <stylesheet file="accumulator-026.xsl"/>
+      </test>
+      <result>
+         <assert-xml><![CDATA[<figures><p>Figure 1: a diagram</p><p>Figure 2: another diagram</p><p>Figure 1: a third diagram</p><p>Figure 2: a fourth diagram</p></figures>]]></assert-xml>
+      </result>
+   </test-case>
+   
+   <test-case name="accumulator-027">
+      <description>Duplicate accumulator name is OK provided there's another with higher precedence</description>
+      <created by="Michael Kay" on="2014-07-07"/>
+      <environment ref="accumulator-001"/>
+      <test>
+         <stylesheet file="accumulator-027.xsl"/>
+      </test>
+      <result>
+         <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-028s">
+      <description>Pattern declared streamable, but @applies-to is not motionless</description>
+      <created by="Michael Kay" on="2014-07-07"/>
+      <environment ref="accumulator-004s"/>
+      <dependencies>
+         <feature value="streaming"/>
+      </dependencies>
+      <test>
+         <stylesheet file="accumulator-028.xsl"/>
+      </test>
+      <result>
+         <error code="XTSE3430"/>
+      </result>
+   </test-case>
+   
+   <test-case name="accumulator-029s">
+      <description>Pattern declared streamable, but accumulator-rule/@match is not motionless</description>
+      <created by="Michael Kay" on="2014-07-07"/>
+      <environment ref="accumulator-004s"/>
+      <dependencies>
+         <feature value="streaming"/>
+      </dependencies>
+      <test>
+         <stylesheet file="accumulator-029.xsl"/>
+      </test>
+      <result>
+         <error code="XTSE3430"/>
+      </result>
+   </test-case>
+   
+   <test-case name="accumulator-030s">
+      <description>Pattern declared streamable, but accumulator-rule/@new-value is not motionless</description>
+      <created by="Michael Kay" on="2014-07-07"/>
+      <environment ref="accumulator-004s"/>
+      <dependencies>
+         <feature value="streaming"/>
+      </dependencies>
+      <test>
+         <stylesheet file="accumulator-030.xsl"/>
+      </test>
+      <result>
+         <error code="XTSE3430"/>
+      </result>
+   </test-case>
+   
+   <test-case name="accumulator-031">
+      <description>Accumulator has circular dependency on global variable</description>
+      <created by="Michael Kay" on="2014-07-07"/>
+      <dependencies>
+         <feature value="streaming"/>
+      </dependencies>
+      <test>
+         <stylesheet file="accumulator-031.xsl"/>
+         <initial-template name="main"/>
+      </test>
+      <result>
+         <error code="XTDE0640"/>
+      </result>
+   </test-case>
+   
+   <test-case name="accumulator-032">
+      <description>Use an accumulator within a global variable (non-streaming)</description>
+      <created by="Michael Kay" on="2014-07-07"/>
+      <dependencies>
+         <feature value="streaming"/>
+      </dependencies>
+      <test>
+         <stylesheet file="accumulator-032.xsl"/>
+         <initial-template name="main"/>
+         <param name="streamable" static="yes" select="'no'"/>
+      </test>
+      <result>
+         <assert>/o = '21'</assert>
+      </result>
+   </test-case>
+   
+   <test-case name="accumulator-032s">
+      <description>Use an accumulator within a global variable (streaming)</description>
+      <created by="Michael Kay" on="2014-07-07"/>
+      <dependencies>
+         <feature value="streaming"/>
+      </dependencies>
+      <test>
+         <stylesheet file="accumulator-032.xsl"/>
+         <initial-template name="main"/>
+         <param name="streamable" static="yes" select="'no'"/>
+      </test>
+      <result>
+         <assert>/o = '21'</assert>
+      </result>
+   </test-case>
+   
+   <test-case name="accumulator-033s">
+      <description>Accumulator @new-value uses global variable</description>
+      <created by="Michael Kay" on="2014-07-07"/>
+      <environment>
+         <source role="." file="accumulator-001.xml" streaming="true"/>
+   	  </environment>
+      <dependencies>
+         <feature value="streaming"/>
+      </dependencies>
+      <test>
+         <stylesheet file="accumulator-033.xsl"/>
+      </test>
+      <result>
+         <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-034">
+      <description>Accumulator patterns use local and global variables</description>
+      <created by="Michael Kay" on="2014-07-07"/>
+      <environment>
+         <source role="." file="accumulator-001.xml" streaming="true"/>
+   	  </environment>
+      <test>
+         <stylesheet file="accumulator-034.xsl"/>
+         <param name="streamable" select="'no'" static="yes"/>
+      </test>
+      <result>
+         <assert-xml><![CDATA[<figures><p>Figure 0: a diagram</p><p>Figure 0: another diagram</p><p>Figure 0: a third diagram</p><p>Figure 0: a fourth diagram</p></figures>]]></assert-xml>
+      </result>
+   </test-case>
+   
+   <test-case name="accumulator-034s">
+      <description>Accumulator patterns use local and global variables (streaming)</description>
+      <created by="Michael Kay" on="2014-07-07"/>
+      <environment>
+         <source role="." file="accumulator-001.xml" streaming="true"/>
+   	  </environment>
+      <dependencies>
+         <feature value="streaming"/>
+      </dependencies>
+      <test>
+         <stylesheet file="accumulator-034.xsl"/>
+         <param name="streamable" select="'yes'" static="yes"/>
+      </test>
+      <result>
+         <assert-xml><![CDATA[<figures><p>Figure 0: a diagram</p><p>Figure 0: another diagram</p><p>Figure 0: a third diagram</p><p>Figure 0: a fourth diagram</p></figures>]]></assert-xml>
+      </result>
+   </test-case>
+   
+   <test-case name="accumulator-035s">
+      <description>Local variables in initial-value and new-value expressions</description>
+      <created by="Michael Kay" on="2014-07-07"/>
+      <environment>
+         <source role="." file="accumulator-001.xml" streaming="true"/>
+   	  </environment>
+      <dependencies>
+         <feature value="streaming"/>
+      </dependencies>
+      <test>
+         <stylesheet file="accumulator-035.xsl"/>
+      </test>
+      <result>
+         <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-set>
\ No newline at end of file
--- a/tests/decl/accumulator/accumulator-001.xsl	Wed Jul 23 16:35:29 2014 +0200
+++ b/tests/decl/accumulator/accumulator-001.xsl	Wed Jul 23 17:02:10 2014 +0200
@@ -4,13 +4,16 @@
   exclude-result-prefixes="xs f" version="3.0">
 
   <!-- Simple test of an accumulator function -->
+  
+  <xsl:param name="streamable" static="yes" select="'no'"/>
 
-  <xsl:accumulator name="figNr" as="xs:integer" initial-value="0" streamable="no">
+  <xsl:accumulator name="figNr" as="xs:integer" initial-value="0" _streamable="{$streamable}">
     <xsl:accumulator-rule match="chap" new-value="0"/>
     <xsl:accumulator-rule match="fig" new-value="$value + 1"/>
   </xsl:accumulator>
 
-  <xsl:mode streamable="no" on-no-match="shallow-skip"/>
+  <xsl:mode _streamable="{$streamable}" on-no-match="shallow-skip"/>
+  
   <xsl:template match="fig">
     <xsl:apply-templates/>
     <p>Figure <xsl:value-of select="accumulator-before('figNr')"/>: <xsl:value-of select="@alt"/></p>
--- a/tests/decl/accumulator/accumulator-002.xsl	Wed Jul 23 16:35:29 2014 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,25 +0,0 @@
-<?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="http://accum001/"
-  exclude-result-prefixes="xs f" version="3.0">
-
-  <!-- Simple test of an accumulator function, with streaming -->
-
-  <xsl:accumulator name="figNr" as="xs:integer" initial-value="0" streamable="yes">
-    <xsl:accumulator-rule match="chap" new-value="0"/>
-    <xsl:accumulator-rule match="fig" new-value="$value + 1"/>
-  </xsl:accumulator>
-
-  <xsl:mode streamable="yes" on-no-match="shallow-skip"/>
-  
-  <xsl:template match="fig">
-    <xsl:apply-templates/>
-    <p>Figure <xsl:value-of select="accumulator-before('figNr')"/>: <xsl:value-of select="@alt"/></p>
-  </xsl:template>
-
-  <xsl:template match="/">
-    <figures>
-      <xsl:apply-templates/>
-    </figures>
-  </xsl:template>
-</xsl:stylesheet>
--- a/tests/decl/accumulator/accumulator-003.xsl	Wed Jul 23 16:35:29 2014 +0200
+++ b/tests/decl/accumulator/accumulator-003.xsl	Wed Jul 23 17:02:10 2014 +0200
@@ -4,14 +4,16 @@
   exclude-result-prefixes="xs f" version="3.0">
 
   <!-- Get pre-descent value of accumulator in both pre-descent and post-descent phase -->
+  
+  <xsl:param name="streamable" static="yes" select="'no'"/>
 
-  <xsl:accumulator name="figNr" as="xs:integer" initial-value="0" streamable="no">
+  <xsl:accumulator name="figNr" as="xs:integer" initial-value="0" _streamable="{$streamable}">
     <xsl:accumulator-rule match="chap" new-value="0"/>
     <xsl:accumulator-rule match="fig" new-value="$value + 1"/>
     <xsl:accumulator-rule match="diag" new-value="5"/>
   </xsl:accumulator>
 
-  <xsl:mode streamable="no" on-no-match="shallow-skip"/>
+  <xsl:mode _streamable="{$streamable}" on-no-match="shallow-skip"/>
   
   <xsl:template match="fig">
     <pix>
--- a/tests/decl/accumulator/accumulator-004.xsl	Wed Jul 23 16:35:29 2014 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,30 +0,0 @@
-<?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="http://accum001/"
-  exclude-result-prefixes="xs f" version="3.0">
-
-  <!-- Get pre-descent value of accumulator in both pre-descent and post-descent phase; streamable -->
-
-
-  <xsl:accumulator name="figNr" as="xs:integer" initial-value="0" streamable="yes">
-    <xsl:accumulator-rule match="chap" new-value="0"/>
-    <xsl:accumulator-rule match="fig" new-value="$value + 1"/>
-    <xsl:accumulator-rule match="diag" new-value="5"/>
-  </xsl:accumulator>
-
-  <xsl:mode streamable="yes" on-no-match="shallow-skip"/>
-
-  <xsl:template match="fig">
-    <pix>
-      <p>Figure <xsl:value-of select="accumulator-before('figNr')"/> start</p>
-      <xsl:apply-templates/>
-      <p>Figure <xsl:value-of select="accumulator-before('figNr')"/> end</p>
-    </pix>
-  </xsl:template>
-
-  <xsl:template match="/">
-    <figures>
-      <xsl:apply-templates/>
-    </figures>
-  </xsl:template>
-</xsl:stylesheet>
--- a/tests/decl/accumulator/accumulator-005.xsl	Wed Jul 23 16:35:29 2014 +0200
+++ b/tests/decl/accumulator/accumulator-005.xsl	Wed Jul 23 17:02:10 2014 +0200
@@ -4,15 +4,17 @@
   exclude-result-prefixes="xs f" version="3.0">
 
   <!-- Get post-descent value of accumulator -->
+  
+  <xsl:param name="streamable" static="yes" select="'no'"/>
 
   <xsl:accumulator name="f:figNr" as="xs:decimal" initial-value="0"
-    streamable="no">
+    _streamable="{$streamable}">
     <xsl:accumulator-rule match="chap" new-value="0"/>
     <xsl:accumulator-rule match="fig" new-value="$value + 1"/>
     <xsl:accumulator-rule match="diag" new-value="$value + 0.5"/>
   </xsl:accumulator>
 
-  <xsl:mode streamable="no" on-no-match="shallow-skip"/>
+  <xsl:mode _streamable="{$streamable}" on-no-match="shallow-skip"/>
   <xsl:template match="fig">
     <pix>
       <p>Figure <xsl:value-of select="accumulator-before('f:figNr')"/> start</p>
--- a/tests/decl/accumulator/accumulator-006.xsl	Wed Jul 23 16:35:29 2014 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,30 +0,0 @@
-<?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="http://accum001/"
-  exclude-result-prefixes="xs f" version="3.0">
-
-  <!-- Get post-descent value of accumulator - streaming version -->
-
-  <xsl:accumulator name="f:figNr" as="xs:decimal" initial-value="0"
-    streamable="yes">
-    <xsl:accumulator-rule match="chap" new-value="0"/>
-    <xsl:accumulator-rule match="fig" new-value="$value + 1"/>
-    <xsl:accumulator-rule match="diag" new-value="$value + 0.5"/>
-  </xsl:accumulator>
-
-  <xsl:mode streamable="yes" on-no-match="shallow-skip"/>
-  <xsl:template match="fig">
-    <pix>
-      <p>Figure <xsl:value-of select="accumulator-before('f:figNr')"/> start</p>
-      <xsl:apply-templates/>
-      <p>Figure <xsl:value-of select="accumulator-after('f:figNr')"/> end</p>
-    </pix>
-  </xsl:template>
-
-
-  <xsl:template match="/">
-    <figures>
-      <xsl:apply-templates/>
-    </figures>
-  </xsl:template>
-</xsl:stylesheet>
--- a/tests/decl/accumulator/accumulator-007.xsl	Wed Jul 23 16:35:29 2014 +0200
+++ b/tests/decl/accumulator/accumulator-007.xsl	Wed Jul 23 17:02:10 2014 +0200
@@ -5,27 +5,37 @@
     exclude-result-prefixes="xs f"
     version="3.0">
     
+    <xsl:param name="applies-to" static="yes" select="'transactions'"/>
+    <xsl:param name="streamable" static="yes" select="'no'"/>
+    <xsl:param name="initial-count" static="yes" select="'0'"/>
+    
     <!-- Use accumulators to compute min, max, sum, avg, and count in parallel -->
+    <!-- Also tests @applies-to -->
     
-   <xsl:accumulator name="count"  as="xs:integer" initial-value="0">
+   <xsl:accumulator name="count"  as="xs:integer" _initial-value="{$initial-count}" 
+   					applies-to="transactions" _streamable="{$streamable}">
      <xsl:accumulator-rule match="transaction" new-value="$value + 1"/>
    </xsl:accumulator>
    
-   <xsl:accumulator name="sum"  as="xs:double" initial-value="0">
+   <xsl:accumulator name="sum"  as="xs:double" initial-value="0" 
+   					applies-to="transactions" _streamable="{$streamable}">
      <xsl:accumulator-rule match="transaction" new-value="$value + @amount"/>
    </xsl:accumulator>
    
-   <xsl:accumulator name="min"  as="xs:double" initial-value="999999999999">
+   <xsl:accumulator name="min"  as="xs:double" initial-value="999999999999" 
+   					_applies-to="{$applies-to}" _streamable="{$streamable}">
      <xsl:accumulator-rule match="transaction" new-value="if (@amount &lt; $value) then @amount else $value"/>
    </xsl:accumulator>
    
-   <xsl:accumulator name="max" as="xs:double" initial-value="-999999999999">
+   <xsl:accumulator name="max" as="xs:double" initial-value="-999999999999" 
+   					_applies-to="{$applies-to}" _streamable="{$streamable}">
      <xsl:accumulator-rule match="transaction" new-value="if (@amount &gt; $value) then @amount else $value"/>
    </xsl:accumulator>
    
    
-   <xsl:mode streamable="no" on-no-match="shallow-skip"/>
+   <xsl:mode _streamable="{$streamable}" on-no-match="deep-skip"/>
    <xsl:template match="/">
+     <xsl:apply-templates/>
      <result min="{accumulator-after('min')}" max="{accumulator-after('max')}" 
              sum="{accumulator-after('sum')}" count="{accumulator-after('count')}" 
              avg="{round(accumulator-after('sum') div accumulator-after('count'), 2)}"/> 
--- a/tests/decl/accumulator/accumulator-008.xsl	Wed Jul 23 16:35:29 2014 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,35 +0,0 @@
-<?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="http://accum004/"
-    exclude-result-prefixes="xs f"
-    version="3.0">
-    
-    <!-- Use accumulators to compute min, max, sum, avg, and count in parallel; streamed case -->
-    
-   <xsl:accumulator name="count" as="xs:integer" initial-value="0" streamable="yes">
-     <xsl:accumulator-rule match="transaction" new-value="$value + 1"/>
-   </xsl:accumulator>
-   
-   <xsl:accumulator name="sum" as="xs:double" initial-value="0" streamable="yes">
-     <xsl:accumulator-rule match="transaction" new-value="$value + @amount"/>
-   </xsl:accumulator>
-   
-   <xsl:accumulator name="min" as="xs:double" initial-value="999999999999" streamable="yes">
-     <xsl:accumulator-rule match="transaction" new-value="if (@amount &lt; $value) then @amount else $value"/>
-   </xsl:accumulator>
-   
-   <xsl:accumulator name="max" as="xs:double" initial-value="-999999999999" streamable="yes">
-     <xsl:accumulator-rule match="transaction" new-value="if (@amount &gt; $value) then @amount else $value"/>
-   </xsl:accumulator>
-   
-   
-   <xsl:mode streamable="yes" on-no-match="deep-skip"/>
-   <xsl:template match="/">
-     <xsl:apply-templates/>
-     <result min="{accumulator-after('min')}" max="{accumulator-after('max')}" 
-             sum="{accumulator-after('sum')}" count="{accumulator-after('count')}" 
-             avg="{round(accumulator-after('sum') div accumulator-after('count'), 2)}"/> 
-   </xsl:template>  
-    
-</xsl:stylesheet>
\ No newline at end of file
--- a/tests/decl/accumulator/accumulator-010.xsl	Wed Jul 23 16:35:29 2014 +0200
+++ b/tests/decl/accumulator/accumulator-010.xsl	Wed Jul 23 17:02:10 2014 +0200
@@ -4,14 +4,16 @@
   exclude-result-prefixes="xs f" version="3.0">
 
   <!-- Use accumulators to compute hierarchic section numbers -->
+  
+  <xsl:param name="streamable" static="yes" select="'no'"/>
 
-  <xsl:accumulator name="f:section-nr" as="xs:integer*" initial-value="0">
+  <xsl:accumulator name="f:section-nr" as="xs:integer*" initial-value="0" _streamable="{$streamable}">
     <xsl:accumulator-rule match="section" phase="start" new-value="0, head($value)+1, tail($value)"/>
     <xsl:accumulator-rule match="section" phase="end" new-value="tail($value) (:pop:)"/>
   </xsl:accumulator>
 
 
-  <xsl:mode streamable="no" on-no-match="shallow-copy"/>
+  <xsl:mode _streamable="{$streamable}" on-no-match="shallow-copy"/>
 
   <xsl:template match="section">
     <span>
--- a/tests/decl/accumulator/accumulator-011.xsl	Wed Jul 23 16:35:29 2014 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,31 +0,0 @@
-<?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="http://accum005/"
-  exclude-result-prefixes="xs f" version="3.0">
-
-  <!-- Use accumulators to compute hierarchic section numbers; with streaming -->
-
-  <xsl:accumulator name="f:section-nr" as="xs:integer*" initial-value="0" streamable="yes">
-    <xsl:accumulator-rule match="section" phase="start" new-value="0, head($value)+1, tail($value)"/>
-    <xsl:accumulator-rule match="section" phase="end" new-value="tail($value) (:pop:)"/>
-  </xsl:accumulator>
-
-
-  <xsl:mode streamable="yes" on-no-match="shallow-copy"/>
-
-  <xsl:template match="section">
-    <span>
-      <xsl:value-of select="reverse(tail(accumulator-before('f:section-nr')))" separator="."/>
-    </span>
-    <xsl:apply-templates/>
-  </xsl:template>
-
-  <xsl:template match="head">
-    <span>
-      <xsl:value-of select="."/>
-    </span>
-  </xsl:template>
-  
-  <xsl:strip-space elements="*"/>
-
-</xsl:stylesheet>
--- a/tests/decl/accumulator/accumulator-012.xsl	Wed Jul 23 16:35:29 2014 +0200
+++ b/tests/decl/accumulator/accumulator-012.xsl	Wed Jul 23 17:02:10 2014 +0200
@@ -4,16 +4,18 @@
   exclude-result-prefixes="xs f" version="3.0">
 
   <!-- Use accumulators to match text nodes -->
+  
+  <xsl:param name="streamable" static="yes" select="'no'"/>
 
   <xsl:accumulator name="f:last-p" 
   					as="xs:string" 
   					initial-value="''"
-  					streamable="no">
+  					_streamable="{$streamable}">
     <xsl:accumulator-rule match="section/p/text()" new-value="string(.)"/>
   </xsl:accumulator>
 
 
-  <xsl:mode streamable="no" on-no-match="shallow-copy"/>
+  <xsl:mode _streamable="{$streamable}" on-no-match="shallow-copy"/>
 
   <xsl:template match="section">
     <xsl:apply-templates/>
--- a/tests/decl/accumulator/accumulator-013.xsl	Wed Jul 23 16:35:29 2014 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,25 +0,0 @@
-<?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="http://accum005/"
-  exclude-result-prefixes="xs f" version="3.0">
-
-  <!-- Use accumulators to match text nodes -->
-
-  <xsl:accumulator name="f:last-p"
-  					as="xs:string" 
-  					initial-value="''"
-  					streamable="yes">
-    <xsl:accumulator-rule match="section/p/text()" new-value="string(.)"/>
-  </xsl:accumulator>
-
-
-  <xsl:mode streamable="yes" on-no-match="shallow-copy"/>
-
-  <xsl:template match="section">
-    <xsl:apply-templates/>
-    <last><xsl:value-of select="accumulator-after('f:last-p')"/></last>
-  </xsl:template>
-
-  <xsl:strip-space elements="*"/>
-
-</xsl:stylesheet>
--- a/tests/decl/accumulator/accumulator-015.xsl	Wed Jul 23 16:35:29 2014 +0200
+++ b/tests/decl/accumulator/accumulator-015.xsl	Wed Jul 23 17:02:10 2014 +0200
@@ -9,10 +9,10 @@
 
    <xsl:mode streamable="yes" />
 
-   <xsl:accumulator name="item-cost"  
+   <xsl:accumulator name="item-cost" streamable="yes" 
        as="xs:integer" 
        initial-value="0">
-       <xsl:accumulator-rule match="cost" new-value="$value + xs:integer(.)"/>
+       <xsl:accumulator-rule match="cost/text()" new-value="$value + xs:integer(.)"/>
    </xsl:accumulator>
    
    <!-- The void xsl:for-each in the template below is designed to sow confusion. Although it does nothing useful,
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/decl/accumulator/accumulator-020.xsl	Wed Jul 23 17:02:10 2014 +0200
@@ -0,0 +1,36 @@
+<?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="http://accum001/"
+  xmlns:f2="http://accum001/"
+  xmlns:g="http://accum002/"
+  exclude-result-prefixes="xs f f2 g" version="3.0">
+
+  <!-- Test valid/invalid accumulator names -->
+  
+  <xsl:param name="one" static="yes" select="'one'"/>
+  <xsl:param name="two" static="yes" select="'two'"/>
+
+  <xsl:accumulator _name="{$one}" as="xs:integer" initial-value="0">
+    <xsl:accumulator-rule match="chap" new-value="0"/>
+    <xsl:accumulator-rule match="fig" new-value="$value + 1"/>
+  </xsl:accumulator>
+  
+  <xsl:accumulator _name="{$two}" as="xs:integer" initial-value="0">
+    <xsl:accumulator-rule match="chap" new-value="0"/>
+    <xsl:accumulator-rule match="fig" new-value="$value + 1"/>
+  </xsl:accumulator>
+
+  <xsl:mode on-no-match="shallow-skip"/>
+  
+  <xsl:template match="fig">
+    <xsl:apply-templates/>
+    <p>Figure <xsl:value-of select="accumulator-before($one)"/>: <xsl:value-of select="@alt"/></p>
+  </xsl:template>
+
+  <xsl:template match="/">
+    <figures>
+      <xsl:apply-templates/>
+    </figures>
+  </xsl:template>
+</xsl:stylesheet>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/decl/accumulator/accumulator-023.xsl	Wed Jul 23 17:02:10 2014 +0200
@@ -0,0 +1,25 @@
+<?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" 
+  exclude-result-prefixes="xs" version="3.0">
+
+  <!-- Import precedence applied to accumulators -->
+  
+  <xsl:import href="accumulator-023a.xsl"/>
+
+  <xsl:accumulator name="a" as="xs:integer" initial-value="0">
+    <xsl:accumulator-rule match="chap" new-value="0"/>
+    <xsl:accumulator-rule match="fig" new-value="$value + 2"/>
+  </xsl:accumulator>
+  
+  <xsl:template match="fig">
+    <xsl:apply-templates/>
+    <p>Figure <xsl:value-of select="accumulator-before('a')"/>: <xsl:value-of select="@alt"/></p>
+  </xsl:template>
+
+  <xsl:template match="/">
+    <figures>
+      <xsl:apply-templates/>
+    </figures>
+  </xsl:template>
+</xsl:stylesheet>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/decl/accumulator/accumulator-023a.xsl	Wed Jul 23 17:02:10 2014 +0200
@@ -0,0 +1,15 @@
+<?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" 
+  exclude-result-prefixes="xs" version="3.0">
+
+  <!-- Import precedence applied to accumulators -->
+
+  <xsl:accumulator name="a" as="xs:integer" initial-value="0">
+    <xsl:accumulator-rule match="chap" new-value="0"/>
+    <xsl:accumulator-rule match="fig" new-value="$value + 1"/>
+  </xsl:accumulator>
+
+  <xsl:mode on-no-match="shallow-skip"/>
+
+</xsl:stylesheet>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/decl/accumulator/accumulator-024.xsl	Wed Jul 23 17:02:10 2014 +0200
@@ -0,0 +1,21 @@
+<?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" 
+  exclude-result-prefixes="xs" version="3.0">
+
+  <!-- An accumulator must have at least one rule -->
+  
+  <xsl:accumulator name="a" as="xs:integer" initial-value="0">
+  </xsl:accumulator>
+  
+  <xsl:template match="fig">
+    <xsl:apply-templates/>
+    <p>Figure <xsl:value-of select="accumulator-before('a')"/>: <xsl:value-of select="@alt"/></p>
+  </xsl:template>
+
+  <xsl:template match="/">
+    <figures>
+      <xsl:apply-templates/>
+    </figures>
+  </xsl:template>
+</xsl:stylesheet>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/decl/accumulator/accumulator-025.xsl	Wed Jul 23 17:02:10 2014 +0200
@@ -0,0 +1,25 @@
+<?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" 
+  exclude-result-prefixes="xs" version="3.0">
+
+  <!-- Initial value is mandatory -->
+  
+  <xsl:import href="accumulator-023a.xsl"/>
+
+  <xsl:accumulator name="a" as="xs:integer">
+    <xsl:accumulator-rule match="chap" new-value="0"/>
+    <xsl:accumulator-rule match="fig" new-value="$value + 2"/>
+  </xsl:accumulator>
+  
+  <xsl:template match="fig">
+    <xsl:apply-templates/>
+    <p>Figure <xsl:value-of select="accumulator-before('a')"/>: <xsl:value-of select="@alt"/></p>
+  </xsl:template>
+
+  <xsl:template match="/">
+    <figures>
+      <xsl:apply-templates/>
+    </figures>
+  </xsl:template>
+</xsl:stylesheet>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/decl/accumulator/accumulator-026.xsl	Wed Jul 23 17:02:10 2014 +0200
@@ -0,0 +1,28 @@
+<?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="http://accum001/"
+  exclude-result-prefixes="xs f" version="3.0">
+
+  <!-- Patterns matching attribute nodes are legal but ignored -->
+  
+  <xsl:param name="streamable" static="yes" select="'no'"/>
+
+  <xsl:accumulator name="figNr" as="xs:integer" initial-value="0" _streamable="{$streamable}">
+    <xsl:accumulator-rule match="chap" new-value="0"/>
+    <xsl:accumulator-rule match="fig" new-value="$value + 1"/>
+    <xsl:accumulator-rule match="@alt" new-value="$value + 100000"/>
+  </xsl:accumulator>
+
+  <xsl:mode _streamable="{$streamable}" on-no-match="shallow-skip"/>
+  
+  <xsl:template match="fig">
+    <xsl:apply-templates/>
+    <p>Figure <xsl:value-of select="accumulator-before('figNr')"/>: <xsl:value-of select="@alt"/></p>
+  </xsl:template>
+
+  <xsl:template match="/">
+    <figures>
+      <xsl:apply-templates/>
+    </figures>
+  </xsl:template>
+</xsl:stylesheet>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/decl/accumulator/accumulator-027.xsl	Wed Jul 23 17:02:10 2014 +0200
@@ -0,0 +1,25 @@
+<?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" 
+  exclude-result-prefixes="xs" version="3.0">
+
+  <!-- Import precedence applied to accumulators -->
+  
+  <xsl:import href="accumulator-027a.xsl"/>
+
+  <xsl:accumulator name="a" as="xs:integer" initial-value="0">
+    <xsl:accumulator-rule match="chap" new-value="0"/>
+    <xsl:accumulator-rule match="fig" new-value="$value + 2"/>
+  </xsl:accumulator>
+  
+  <xsl:template match="fig">
+    <xsl:apply-templates/>
+    <p>Figure <xsl:value-of select="accumulator-before('a')"/>: <xsl:value-of select="@alt"/></p>
+  </xsl:template>
+
+  <xsl:template match="/">
+    <figures>
+      <xsl:apply-templates/>
+    </figures>
+  </xsl:template>
+</xsl:stylesheet>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/decl/accumulator/accumulator-027a.xsl	Wed Jul 23 17:02:10 2014 +0200
@@ -0,0 +1,20 @@
+<?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" 
+  exclude-result-prefixes="xs" version="3.0">
+
+  <!-- Import precedence applied to accumulators -->
+
+  <xsl:accumulator name="a" as="xs:integer" initial-value="0">
+    <xsl:accumulator-rule match="chap" new-value="0"/>
+    <xsl:accumulator-rule match="fig" new-value="$value + 83"/>
+  </xsl:accumulator>
+  
+  <xsl:accumulator name="a" as="xs:integer" initial-value="0">
+    <xsl:accumulator-rule match="chap" new-value="0"/>
+    <xsl:accumulator-rule match="fig" new-value="$value + 86"/>
+  </xsl:accumulator>
+
+  <xsl:mode on-no-match="shallow-skip"/>
+
+</xsl:stylesheet>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/decl/accumulator/accumulator-028.xsl	Wed Jul 23 17:02:10 2014 +0200
@@ -0,0 +1,25 @@
+<?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" 
+  exclude-result-prefixes="xs" version="3.0">
+
+  <!-- Accumulator declared streamable, but @applies-to is not motionless -->
+  
+  <xsl:mode streamable="yes"/>
+  
+  <xsl:accumulator name="a" as="xs:integer" initial-value="0" applies-to="doc[chap]" streamable="yes">
+    <xsl:accumulator-rule match="chap" new-value="0"/>
+    <xsl:accumulator-rule match="fig" new-value="$value + 2"/>
+  </xsl:accumulator>
+  
+  <xsl:template match="fig">
+    <xsl:apply-templates/>
+    <p>Figure <xsl:value-of select="accumulator-before('a')"/>: <xsl:value-of select="@alt"/></p>
+  </xsl:template>
+
+  <xsl:template match="/">
+    <figures>
+      <xsl:apply-templates/>
+    </figures>
+  </xsl:template>
+</xsl:stylesheet>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/decl/accumulator/accumulator-029.xsl	Wed Jul 23 17:02:10 2014 +0200
@@ -0,0 +1,25 @@
+<?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" 
+  exclude-result-prefixes="xs" version="3.0">
+
+  <!-- Accumulator declared streamable, but accumulator-rule/@match is not motionless -->
+  
+  <xsl:mode streamable="yes"/>
+  
+  <xsl:accumulator name="a" as="xs:integer" initial-value="0" applies-to="doc[chap]" streamable="yes">
+    <xsl:accumulator-rule match="chap" new-value="0"/>
+    <xsl:accumulator-rule match="fig[caption]" new-value="$value + 2"/>
+  </xsl:accumulator>
+  
+  <xsl:template match="fig">
+    <xsl:apply-templates/>
+    <p>Figure <xsl:value-of select="accumulator-before('a')"/>: <xsl:value-of select="@alt"/></p>
+  </xsl:template>
+
+  <xsl:template match="/">
+    <figures>
+      <xsl:apply-templates/>
+    </figures>
+  </xsl:template>
+</xsl:stylesheet>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/decl/accumulator/accumulator-030.xsl	Wed Jul 23 17:02:10 2014 +0200
@@ -0,0 +1,25 @@
+<?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" 
+  exclude-result-prefixes="xs" version="3.0">
+
+  <!-- Accumulator declared streamable, but accumulator-rule/@match is not motionless -->
+  
+  <xsl:mode streamable="yes"/>
+  
+  <xsl:accumulator name="a" as="xs:integer" initial-value="0" applies-to="doc[chap]" streamable="yes">
+    <xsl:accumulator-rule match="chap" new-value="0"/>
+    <xsl:accumulator-rule match="fig" new-value="$value + string-length(caption)"/>
+  </xsl:accumulator>
+  
+  <xsl:template match="fig">
+    <xsl:apply-templates/>
+    <p>Figure <xsl:value-of select="accumulator-before('a')"/>: <xsl:value-of select="@alt"/></p>
+  </xsl:template>
+
+  <xsl:template match="/">
+    <figures>
+      <xsl:apply-templates/>
+    </figures>
+  </xsl:template>
+</xsl:stylesheet>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/decl/accumulator/accumulator-031.xsl	Wed Jul 23 17:02:10 2014 +0200
@@ -0,0 +1,24 @@
+<?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" 
+  exclude-result-prefixes="xs" version="3.0">
+
+  <!-- Accumulator has circular dependency on global variable -->
+  
+  <xsl:mode streamable="yes"/>
+  
+  <xsl:accumulator name="a" as="xs:integer" initial-value="0" streamable="yes">
+    <xsl:accumulator-rule match="*" new-value="$value + $count"/>
+  </xsl:accumulator>
+
+  <xsl:variable name="count">
+    <xsl:stream href="accumulator-001.xml">
+      <xsl:for-each select="*"/>
+      <xsl:value-of select="accumulator-after('a')"/>
+    </xsl:stream>
+  </xsl:variable>
+  
+  <xsl:template name="main">
+    <o><xsl:value-of select="$count"/></o>
+  </xsl:template>
+</xsl:stylesheet>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/decl/accumulator/accumulator-032.xsl	Wed Jul 23 17:02:10 2014 +0200
@@ -0,0 +1,33 @@
+<?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" 
+  exclude-result-prefixes="xs" version="3.0">
+
+  <!-- Use an accumulator within a global variable -->
+  
+  <xsl:param name="streamable" static="yes" required="yes"/>
+  
+  <xsl:mode _streamable="{$streamable}"/>
+  
+  <xsl:accumulator name="a" as="xs:integer" initial-value="0" streamable="yes">
+    <xsl:accumulator-rule match="*" new-value="$value + 1"/>
+  </xsl:accumulator>
+
+  <xsl:variable name="count" use-when="$streamable='yes'">
+    <xsl:stream href="accumulator-001.xml">
+      <!--<xsl:for-each select="*"/>-->
+      <xsl:value-of select="accumulator-after('a')"/>
+    </xsl:stream>
+  </xsl:variable>
+  
+  <xsl:variable name="count" use-when="$streamable='no'">
+    <xsl:for-each select="doc('accumulator-001.xml')">
+      <!--<xsl:for-each select="*"/>-->
+      <xsl:value-of select="accumulator-after('a')"/>
+    </xsl:for-each>
+  </xsl:variable>
+  
+  <xsl:template name="main">
+    <o><xsl:value-of select="$count"/></o>
+  </xsl:template>
+</xsl:stylesheet>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/decl/accumulator/accumulator-033.xsl	Wed Jul 23 17:02:10 2014 +0200
@@ -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" 
+  exclude-result-prefixes="xs" version="3.0">
+
+  <!-- Accumulator has dependency on global variable -->
+  
+  <xsl:mode streamable="no" on-no-match="shallow-skip"/>
+  
+  <xsl:accumulator name="a" as="xs:integer" initial-value="0">
+    <xsl:accumulator-rule match="chap" new-value="0"/>
+    <xsl:accumulator-rule match="fig" new-value="$value + $count"/>
+  </xsl:accumulator>
+  
+  <xsl:template match="fig">
+    <xsl:apply-templates/>
+    <p>Figure <xsl:value-of select="accumulator-before('a')"/>: <xsl:value-of select="@alt"/></p>
+  </xsl:template>
+
+  <xsl:template match="/">
+    <figures>
+      <xsl:apply-templates/>
+    </figures>
+  </xsl:template>
+  
+  <xsl:variable name="count" select="2"/>
+</xsl:stylesheet>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/decl/accumulator/accumulator-034.xsl	Wed Jul 23 17:02:10 2014 +0200
@@ -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" 
+  exclude-result-prefixes="xs" version="3.0">
+
+  <!-- Accumulator pattern has dependency on global variable and local variable -->
+  
+  <xsl:param name="streamable" static="yes" required="yes"/>
+  
+  <xsl:mode _streamable="{$streamable}" on-no-match="shallow-skip"/>
+  
+  <xsl:accumulator name="a" as="xs:integer" initial-value="0" _streamable="{$streamable}">
+    <xsl:accumulator-rule match="chap[not(@nr = $seven)]" new-value="0"/>
+    <xsl:accumulator-rule match="fig[every $n in data(@*) satisfies $n = '83']" new-value="$value + 2"/>
+  </xsl:accumulator>
+  
+  <xsl:template match="fig">
+    <xsl:apply-templates/>
+    <p>Figure <xsl:value-of select="accumulator-before('a')"/>: <xsl:value-of select="@alt"/></p>
+  </xsl:template>
+
+  <xsl:template match="/">
+    <figures>
+      <xsl:apply-templates/>
+    </figures>
+  </xsl:template>
+  
+  <xsl:variable name="seven" select="7"/>
+</xsl:stylesheet>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/decl/accumulator/accumulator-035.xsl	Wed Jul 23 17:02:10 2014 +0200
@@ -0,0 +1,28 @@
+<?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" 
+  exclude-result-prefixes="xs" version="3.0">
+
+  <!-- Local variables in initial-value and new-value expressions -->
+  
+  <xsl:mode streamable="yes" on-no-match="shallow-skip"/>
+  
+  <xsl:accumulator name="a" as="xs:integer" initial-value="min(for $i in $zero to 5 return $i*2)"
+  			streamable="yes">
+    <xsl:accumulator-rule match="chap" new-value="0"/>
+    <xsl:accumulator-rule match="fig" new-value="$value + min(for $i in ($zero+1) to 5 return $i*2)"/>
+  </xsl:accumulator>
+  
+  <xsl:template match="fig">
+    <xsl:apply-templates/>
+    <p>Figure <xsl:value-of select="accumulator-before('a')"/>: <xsl:value-of select="@alt"/></p>
+  </xsl:template>
+
+  <xsl:template match="/">
+    <figures>
+      <xsl:apply-templates/>
+    </figures>
+  </xsl:template>
+  
+  <xsl:param name="zero" select="0"/>
+</xsl:stylesheet>
--- a/tests/decl/output/_output-test-set.xml	Wed Jul 23 16:35:29 2014 +0200
+++ b/tests/decl/output/_output-test-set.xml	Wed Jul 23 17:02:10 2014 +0200
@@ -31,6 +31,22 @@
       <source role="." file="output04.xml"/>
    </environment>
    
+   <!-- Test environments for HTML5 -->
+   <environment name="output-06a">
+      <stylesheet file="output-0601.xsl"/>
+      <source role="." file="output06a.xml">
+         <description>An XML/HTML tree containing prefixed elements in SVG, MathML and a foreign
+            namespace</description>
+      </source>
+   </environment>
+   <environment name="output-06b">
+      <stylesheet file="output-0601.xsl"/>
+      <source role="." file="output06b.xml">
+         <description>An XML/HTML tree containing prefixed attributes in SVG, MathML and a foreign
+            namespace</description>
+      </source>
+   </environment>
+   
    <test-case name="output-0101">
       <description>Test escaping of non-ASCII characters in HTML output when @escape-uri-attributes= yes.</description>
       <created by="Michael Kay" on="2012-10-30"/>
@@ -2882,4 +2898,177 @@
          <error code="XTSE0010"/>
       </result>
    </test-case>
+   
+   
+   <!-- Tests for HTML5 -->
+   
+   <test-case name="output-0601">
+      <description>HTML5 empty content elements</description>
+      <created by="John Lumley" on="2014-06-19"/>
+      <environment>
+         <source role="." file="output06c.xml"/>
+      </environment>
+      <dependencies>
+         <spec value="XSLT20+"/>
+      </dependencies>
+      <test>
+         <stylesheet file="output-0601.xsl"/>
+      </test>
+      <result>
+         <all-of>
+            <serialization-matches><![CDATA[<area\s*>]]></serialization-matches>
+            <serialization-matches><![CDATA[<base\s*>]]></serialization-matches>
+            <serialization-matches><![CDATA[<br\s*>]]></serialization-matches>
+            <serialization-matches><![CDATA[<col\s*>]]></serialization-matches>
+            <serialization-matches><![CDATA[<command\s*>]]></serialization-matches>
+            <serialization-matches><![CDATA[<embed\s*>]]></serialization-matches>
+            <serialization-matches><![CDATA[<hr\s*>]]></serialization-matches>
+            <serialization-matches><![CDATA[<img\s*>]]></serialization-matches>
+            <serialization-matches><![CDATA[<input\s*>]]></serialization-matches>
+            <serialization-matches><![CDATA[<keygen\s*>]]></serialization-matches>
+            <serialization-matches><![CDATA[<link\s*>]]></serialization-matches>
+            <serialization-matches><![CDATA[<meta\s*>]]></serialization-matches>
+            <serialization-matches><![CDATA[<param\s*>]]></serialization-matches>
+            <serialization-matches><![CDATA[<source\s*>]]></serialization-matches>
+            <serialization-matches><![CDATA[<track\s*>]]></serialization-matches>
+            <serialization-matches><![CDATA[<wbr\s*>]]></serialization-matches>
+         </all-of>
+      </result>
+   </test-case>
+   
+   <test-case name="output-0602a">
+      <description>HTML5 svg unprefixed</description>
+      <created by="John Lumley" on="2014-07-15"/>
+      <environment ref="output-06a"/>
+      <dependencies>
+         <spec value="XSLT20+"/>
+      </dependencies>
+      <test>
+         <!--<stylesheet file="output-0601.xsl"/>-->
+      </test>
+      <result>
+         <all-of>
+            <not>
+               <any-of>
+                  <serialization-matches><![CDATA[<body\s+xmlns=["']http://www.w3.org/2000/svg["']]]></serialization-matches>
+                  <serialization-matches>xmlns:svg=["']http://www.w3.org/2000/svg["']</serialization-matches>
+               </any-of>
+            </not>
+            <serialization-matches><![CDATA[<svg\s+xmlns=["']http://www.w3.org/2000/svg["']]]></serialization-matches>
+         </all-of>
+      </result>
+   </test-case>
+   <test-case name="output-0602b">
+      <description>HTML5 MathML unprefixed</description>
+      <created by="John Lumley" on="2014-07-15"/>
+      <environment ref="output-06a"/>
+      <dependencies>
+         <spec value="XSLT20+"/>
+      </dependencies>
+      <test>         
+      </test>
+      <result>
+         <all-of>
+            <not>
+               <any-of>
+                  <serialization-matches>xmlns:mathML=["']http://www.w3.org/1998/Math/MathML["']</serialization-matches>
+               </any-of>
+            </not>
+            <serialization-matches><![CDATA[<math\s+xmlns=["']http://www.w3.org/1998/Math/MathML["']]]></serialization-matches>
+         </all-of>
+      </result>
+   </test-case>
+   <test-case name="output-0602c">
+      <description>HTML5 foreign namespace prefixed</description>
+      <created by="John Lumley" on="2014-07-15"/>
+      <environment ref="output-06a"/>
+      <dependencies>
+         <spec value="XSLT20+"/>
+      </dependencies>
+      <test>
+        
+      </test>
+      <result>
+         <all-of>
+            <serialization-matches>xmlns:n=["']NamespaceN["']</serialization-matches>
+            <serialization-matches><![CDATA[<n:zzz>]]></serialization-matches>
+         </all-of>
+      </result>
+   </test-case>
+   
+   <test-case name="output-0603a">
+      <description>HTML5 svg:attribute prefixed</description>
+      <created by="John Lumley" on="2014-07-15"/>
+      <environment ref="output-06b"/>
+      <dependencies>
+         <spec value="XSLT20+"/>
+      </dependencies>
+      <test>
+         
+      </test>
+      <result>
+         <all-of>
+            <serialization-matches>mi\s+xmlns:svg=["']http://www.w3.org/2000/svg["']</serialization-matches>
+            <serialization-matches>svg:att=</serialization-matches>
+         </all-of>
+      </result>
+   </test-case>
+   <test-case name="output-0603b">
+      <description>HTML5 MathML:attribute prefixed</description>
+      <created by="John Lumley" on="2014-07-15"/>
+      <environment ref="output-06b"/>
+      <dependencies>
+         <spec value="XSLT20+"/>
+      </dependencies>
+      <test>
+         
+      </test>
+      <result>
+         <all-of>
+            <serialization-matches>xmlns:mathML=["']http://www.w3.org/1998/Math/MathML["']</serialization-matches>
+            <serialization-matches>mathML:att=</serialization-matches>
+         </all-of>
+      </result>
+   </test-case>
+   <test-case name="output-0603c">
+      <description>HTML5 foreign namespace attribute prefixed</description>
+      <created by="John Lumley" on="2014-07-15"/>
+      <environment ref="output-06b"/>
+      <dependencies>
+         <spec value="XSLT20+"/>
+      </dependencies>
+      <test>
+         
+      </test>
+      <result>
+         <all-of>
+            <serialization-matches>xmlns:m=["']NamespaceM["']</serialization-matches>
+            <serialization-matches><![CDATA[<p m:zzz=["']value["']>]]></serialization-matches>
+         </all-of>
+      </result>
+   </test-case>
+   
+   
+   <test-case name="output-0604">
+      <description>HTML5 - test simple use of a character map</description>
+      <created by="John Lumley" on="2014-07-18"/>
+      <environment>
+         <source role=".">
+            <content><![CDATA[<doc><a value="abcde">vwxyz</a></doc>]]></content>
+         </source>
+      </environment>
+      <dependencies>
+         <spec value="XSLT20+"/>
+      </dependencies>
+      <test>
+         <stylesheet file="output-0602.xsl"/>
+      </test>
+      <result>
+         <all-of>
+            <serialization-matches>value=['"]ab\[C\]de['"]</serialization-matches>
+            <serialization-matches>vw\[X\]yz</serialization-matches>
+         </all-of>
+      </result>
+   </test-case>
+   
 </test-set>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/decl/output/output-0601.xsl	Wed Jul 23 17:02:10 2014 +0200
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<t:transform xmlns:t="http://www.w3.org/1999/XSL/Transform"
+   xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"
+   version="3.0">
+   <!-- Purpose: Test namespace prefixing of SVG/MathML etc in HTML5-->
+
+   <t:output method="html" version="5.0" html-version="5.0" escape-uri-attributes="yes"
+      encoding="UTF-8" indent="yes"/>
+   <t:strip-space elements="*"/>
+
+   <t:template match="/">
+      <t:copy-of select="*"/>
+   </t:template>
+
+</t:transform>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/decl/output/output-0602.xsl	Wed Jul 23 17:02:10 2014 +0200
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<t:transform xmlns:t="http://www.w3.org/1999/XSL/Transform"
+   xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"
+   version="3.0">
+   <!-- Purpose: Test character map support in HTML5-->
+   <t:character-map name="map01">
+      <t:output-character character="c" string="[C]"/>
+      <t:output-character character="x" string="[X]"/>
+   </t:character-map>
+   <t:output method="html" version="5.0" html-version="5.0" escape-uri-attributes="yes"
+      encoding="UTF-8" indent="yes"  use-character-maps="map01"/>
+   <t:strip-space elements="*"/>
+
+   <t:template match="/">
+      <t:copy-of select="*"/>
+   </t:template>
+
+</t:transform>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/decl/output/output06a.xml	Wed Jul 23 17:02:10 2014 +0200
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<html xmlns:n="NamespaceN">
+  <head>
+    <title>OUTPUT-METHOD</title>
+  </head>
+  <body xmlns:svg="http://www.w3.org/2000/svg">
+    <p>This stylesheet generates<br />some output</p>
+    <n:zzz>Foreign namespace</n:zzz>
+    <svg:svg width="100" height="100">
+      <rect xmlns="http://www.w3.org/2000/svg" fill="yellow" width="100" height="100"></rect>
+      <svg:circle fill="red" cx="30" cy="30" r="20"></svg:circle>
+    </svg:svg>
+    <mathML:math xmlns:mathML="http://www.w3.org/1998/Math/MathML">
+      <mrow xmlns="http://www.w3.org/1998/Math/MathML">
+        <mi>a</mi>
+        <mathML:msup>
+          <mi>x</mi>
+          <mn>2</mn>
+        </mathML:msup>
+        <mo>+</mo>
+        <mi>b</mi>
+      </mrow>
+    </mathML:math>
+  </body>
+</html>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/decl/output/output06b.xml	Wed Jul 23 17:02:10 2014 +0200
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<html xmlns:n="NamespaceN" xmlns:m="NamespaceM">
+  <head>
+    <title>OUTPUT-METHOD</title>
+  </head>
+  <body xmlns:svg="http://www.w3.org/2000/svg">
+    <p>This stylesheet generates<br />some output</p>
+    <n:zzz>Foreign namespace</n:zzz>
+    <p m:zzz="value">Foreign attribute</p>
+    <svg:svg width="100" height="100">
+      <rect xmlns="http://www.w3.org/2000/svg" fill="yellow" width="100" height="100"></rect>
+      <svg:circle fill="red" cx="30" cy="30" r="20"></svg:circle>
+    </svg:svg>
+    <mathML:math xmlns:mathML="http://www.w3.org/1998/Math/MathML">
+      <mrow xmlns="http://www.w3.org/1998/Math/MathML">
+        <mi svg:att="34" z="5" mathML:att="123" svg:atZZZ="99">a</mi>
+        <mathML:msup>
+          <mi>x</mi>
+          <mn>2</mn>
+        </mathML:msup>
+        <mo>+</mo>
+        <mi>b</mi>
+      </mrow>
+    </mathML:math>
+  </body>
+</html>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/decl/output/output06c.xml	Wed Jul 23 17:02:10 2014 +0200
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<html>
+  <head>
+    <title>test</title>
+  </head>
+  <body>
+    <area/>
+    <base/>
+    <br/>
+    <col/>
+    <command/>
+    <embed/>
+    <hr/>
+    <img/>
+    <input/>
+    <keygen/>
+    <link/>
+    <meta/>
+    <param/>
+    <source/>
+    <track/>
+    <wbr/>
+  </body>
+</html>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fn/current-output-uri/_current-output-uri-test-set.xml	Wed Jul 23 17:02:10 2014 +0200
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<test-set xmlns:xs="http://www.w3.org/2001/XMLSchema"
+          xmlns="http://www.w3.org/2012/10/xslt-test-catalog"
+          name="current-output-uri">
+   <description>Tests current-output-uri() function in XSLT 3.0</description>
+   
+   <dependencies>
+       <spec value="XSLT30+"/>
+   </dependencies>
+
+   <test-case name="current-output-uri-001">
+      <description>Returns empty sequence in temporary output state</description>
+      <created by="Michael Kay" on="2014-07-12"/>      
+      <test>
+         <stylesheet file="current-output-uri-001.xsl"/>
+         <initial-template name="main"/>
+      </test>
+      <result>
+         <assert-xml><![CDATA[<ok/>]]></assert-xml>
+      </result>
+   </test-case>
+   
+   <test-case name="current-output-uri-002">
+      <description>Initial value of current-output-uri</description>
+      <created by="Michael Kay" on="2014-07-12"/>      
+      <test>
+         <stylesheet file="current-output-uri-002.xsl"/>
+         <initial-template name="main"/>
+         <output file="results/current-output-uri-002.xml"/>
+      </test>
+      <result>
+         <assert>ends-with(/out, 'fn/current-output-uri/results/current-output-uri-002.xml')</assert>
+      </result>
+   </test-case>
+   
+   <test-case name="current-output-uri-003">
+      <description>Value of current-output-uri() within xsl:result-document</description>
+      <created by="Michael Kay" on="2014-07-12"/>      
+      <test>
+         <stylesheet file="current-output-uri-003.xsl"/>
+         <initial-template name="main"/>
+         <output file="results/current-output-uri-003.xml"/>
+      </test>
+      <result>
+         <assert-result-document uri="second/current-output-uri-003.xml">
+            <assert>ends-with(/out, 'fn/current-output-uri/results/second/current-output-uri-003.xml')</assert>
+         </assert-result-document>
+      </result>
+   </test-case>
+   
+   
+   
+
+
+</test-set>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fn/current-output-uri/current-output-uri-001.xsl	Wed Jul 23 17:02:10 2014 +0200
@@ -0,0 +1,17 @@
+<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+  xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs">
+
+  <!-- current-output-uri() in temporary output state -->
+
+  <xsl:variable name="v">
+    <xsl:choose>
+      <xsl:when test="empty(current-output-uri())"><ok/></xsl:when>
+      <xsl:otherwise><wrong result="{current-output-uri()}"/></xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
+  
+  <xsl:template name="main">
+    <xsl:copy-of select="$v"/>
+  </xsl:template>
+
+</xsl:stylesheet>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fn/current-output-uri/current-output-uri-002.xsl	Wed Jul 23 17:02:10 2014 +0200
@@ -0,0 +1,10 @@
+<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+  xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs">
+
+  <!-- current-output-uri() initial value -->
+  
+  <xsl:template name="main">
+    <out><xsl:value-of select="current-output-uri()"/></out>
+  </xsl:template>
+
+</xsl:stylesheet>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fn/current-output-uri/current-output-uri-003.xsl	Wed Jul 23 17:02:10 2014 +0200
@@ -0,0 +1,12 @@
+<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+  xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs">
+
+  <!-- current-output-uri() within xsl:result-document -->
+  
+  <xsl:template name="main">
+    <xsl:result-document href="second/current-output-uri-003.xml">
+    	<out><xsl:value-of select="current-output-uri()"/></out>
+    </xsl:result-document>	
+  </xsl:template>
+
+</xsl:stylesheet>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fn/json-to-xml/_json-to-xml-test-set.xml	Wed Jul 23 17:02:10 2014 +0200
@@ -0,0 +1,494 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<test-set xmlns:xs="http://www.w3.org/2001/XMLSchema"
+    xmlns="http://www.w3.org/2012/10/xslt-test-catalog"
+    xmlns:j="http://www.w3.org/2013/XSL/json"
+    name="json-to-xml">
+    <description>json-to-xml() function</description>
+    
+    <!-- NOTE: currently missing tests for string escaping -->
+
+    <environment name="json-to-xml-A">
+        <stylesheet file="json-to-xml-A.xsl"/>
+    </environment>
+    
+    <environment name="json-to-xml-E">
+        <stylesheet file="json-to-xml-E.xsl"/>
+    </environment>
+
+
+
+    <dependencies>
+        <spec value="XSLT30+"/>
+    </dependencies>
+    
+    
+    <test-case name="json-to-xml-001">
+        <description>Empty object as document-node</description>
+        <created by="John Lumley" on="2013-10-01"/>
+        <environment ref="json-to-xml-A"/>
+        <test><initial-template name="json-to-xml-001"/></test>
+        <result>
+            <assert-xml><![CDATA[<j:map xmlns:j="http://www.w3.org/2013/XSL/json"/>]]></assert-xml>
+        </result>
+    </test-case>
+    
+    <test-case name="json-to-xml-002">
+        <description>Empty object</description>
+        <created by="John Lumley" on="2013-10-01"/>
+        <environment ref="json-to-xml-A"/>
+        <test><initial-template name="json-to-xml-002"/></test>
+        <result>
+            <assert-xml><![CDATA[<j:map xmlns:j="http://www.w3.org/2013/XSL/json"/>]]></assert-xml>
+        </result>
+    </test-case>
+    
+    <test-case name="json-to-xml-003">
+        <description>Empty array as document-node</description>
+        <created by="John Lumley" on="2013-10-01"/>
+        <environment ref="json-to-xml-A"/>
+        <test><initial-template name="json-to-xml-003"/></test>
+        <result>
+            <assert-xml><![CDATA[<j:array xmlns:j="http://www.w3.org/2013/XSL/json"/>]]></assert-xml>
+        </result>
+    </test-case>
+    
+    <test-case name="json-to-xml-004">
+        <description>Empty array</description>
+        <created by="John Lumley" on="2013-10-01"/>
+        <environment ref="json-to-xml-A"/>
+        <test><initial-template name="json-to-xml-004"/></test>
+        <result>
+            <assert-xml><![CDATA[<j:array xmlns:j="http://www.w3.org/2013/XSL/json"/>]]></assert-xml>
+        </result>
+    </test-case>
+    
+    <test-case name="json-to-xml-005">
+        <description>Array Number</description>
+        <created by="John Lumley" on="2013-10-01"/>
+        <environment ref="json-to-xml-A"/>
+        <test><initial-template name="json-to-xml-005"/></test>
+        <result>
+            <assert-xml><![CDATA[<j:array xmlns:j="http://www.w3.org/2013/XSL/json"><j:number>1</j:number></j:array>]]></assert-xml>
+        </result>
+    </test-case>
+    
+    <test-case name="json-to-xml-006">
+        <description>Array String</description>
+        <created by="John Lumley" on="2013-10-01"/>
+        <environment ref="json-to-xml-A"/>
+        <test><initial-template name="json-to-xml-006"/></test>
+        <result>
+            <assert-xml><![CDATA[<j:array xmlns:j="http://www.w3.org/2013/XSL/json"><j:string>a</j:string></j:array>]]></assert-xml>
+        </result>
+    </test-case>
+    
+    <test-case name="json-to-xml-007">
+        <description>Array True</description>
+        <created by="John Lumley" on="2013-10-01"/>
+        <environment ref="json-to-xml-A"/>
+        <test><initial-template name="json-to-xml-007"/></test>
+        <result>
+            <assert-xml><![CDATA[<j:array xmlns:j="http://www.w3.org/2013/XSL/json"><j:boolean>true</j:boolean></j:array>]]></assert-xml>
+        </result>
+    </test-case>
+    
+    <test-case name="json-to-xml-008">
+        <description>Array False</description>
+        <created by="John Lumley" on="2013-10-01"/>
+        <environment ref="json-to-xml-A"/>
+        <test><initial-template name="json-to-xml-008"/></test>
+        <result>
+            <assert-xml><![CDATA[<j:array xmlns:j="http://www.w3.org/2013/XSL/json"><j:boolean>false</j:boolean></j:array>]]></assert-xml>
+        </result>
+    </test-case>
+    
+    <test-case name="json-to-xml-009">
+        <description>Array Null</description>
+        <created by="John Lumley" on="2013-10-01"/>
+        <environment ref="json-to-xml-A"/>
+        <test><initial-template name="json-to-xml-009"/></test>
+        <result>
+            <assert-xml><![CDATA[<j:array xmlns:j="http://www.w3.org/2013/XSL/json"><j:null/></j:array>]]></assert-xml>
+        </result>
+    </test-case>
+    
+    <test-case name="json-to-xml-010">
+        <description>Larger JSON input</description>
+        <created by="John Lumley" on="2013-10-01"/>
+        <environment ref="json-to-xml-A"/>
+        <test><initial-template name="json-to-xml-010"/></test>
+        <result>
+            <all-of>
+                <assert>/j:map/j:map[@key='glossary']/j:string[@key='title']</assert>
+                <assert>/j:map/j:map[@key='glossary']/j:map[@key='GlossDiv']</assert>
+            </all-of>
+        </result>
+    </test-case>
+    
+    <test-case name="json-to-xml-011">
+        <description>Larger JSON input</description>
+        <created by="John Lumley" on="2013-10-01"/>
+        <environment ref="json-to-xml-A"/>
+        <test><initial-template name="json-to-xml-011"/></test>
+        <result>
+            <all-of>
+                <assert>/j:map/j:map[@key='menu']/j:string[@key='header'][.='SVG Viewer']</assert>
+                <assert>/j:map/j:map[@key='menu']/j:array[@key='items']/j:map[not(@*)]/j:string[@key='id'][.='Open']</assert>
+            </all-of>
+        </result>
+    </test-case>
+    
+    <test-case name="json-to-xml-012">
+        <description>Escaped text</description>
+        <created by="John Lumley" on="2013-10-01"/>
+        <environment ref="json-to-xml-A"/>
+        <test><initial-template name="json-to-xml-012"/></test>
+        <result>
+            <assert-xml><![CDATA[<j:map xmlns:j="http://www.w3.org/2013/XSL/json"><j:string key="key">Data with " within it</j:string></j:map>]]></assert-xml>
+        </result>
+    </test-case>
+    
+
+    <test-case name="json-to-xml-error-001">
+        <description>Empty string</description>
+        <created by="John Lumley" on="2013-10-01"/>
+        <environment ref="json-to-xml-E"/>
+        <test>
+            <initial-template name="json-to-xml-error-001"/>
+        </test>
+        <result>
+            <error code="XTDE3240"/>
+        </result>
+    </test-case>
+    
+    <test-case name="json-to-xml-error-002">
+        <description>Unknown token</description>
+        <created by="John Lumley" on="2013-10-01"/>
+        <environment ref="json-to-xml-E"/>
+        <test>
+            <initial-template name="json-to-xml-error-002"/>
+        </test>
+        <result>
+            <error code="XTDE3240"/>
+        </result>
+    </test-case>
+    
+    <test-case name="json-to-xml-error-003">
+        <description>Unknown token</description>
+        <created by="John Lumley" on="2013-10-01"/>
+        <environment ref="json-to-xml-E"/>
+        <test>
+            <initial-template name="json-to-xml-error-003"/>
+        </test>
+        <result>
+            <error code="XTDE3240"/>
+        </result>
+    </test-case>
+    
+    <test-case name="json-to-xml-error-004">
+        <description>Extra token</description>
+        <created by="John Lumley" on="2013-10-01"/>
+        <environment ref="json-to-xml-E"/>
+        <test>
+            <initial-template name="json-to-xml-error-004"/>
+        </test>
+        <result>
+            <error code="XTDE3240"/>
+        </result>
+    </test-case>
+    
+    <test-case name="json-to-xml-error-005">
+        <description>Non-string key</description>
+        <created by="John Lumley" on="2013-10-01"/>
+        <environment ref="json-to-xml-E"/>
+        <test>
+            <initial-template name="json-to-xml-error-005"/>
+        </test>
+        <result>
+            <error code="XTDE3240"/>
+        </result>
+    </test-case>
+    
+    <test-case name="json-to-xml-error-006">
+        <description>Non-string key</description>
+        <created by="John Lumley" on="2013-10-01"/>
+        <environment ref="json-to-xml-E"/>
+        <test>
+            <initial-template name="json-to-xml-error-006"/>
+        </test>
+        <result>
+            <error code="XTDE3240"/>
+        </result>
+    </test-case>
+    
+    <test-case name="json-to-xml-error-007">
+        <description>Missing colon after key</description>
+        <created by="John Lumley" on="2013-10-01"/>
+        <environment ref="json-to-xml-E"/>
+        <test>
+            <initial-template name="json-to-xml-error-007"/>
+        </test>
+        <result>
+            <error code="XTDE3240"/>
+        </result>
+    </test-case>
+    
+    <test-case name="json-to-xml-error-008">
+        <description>Extra token after map value</description>
+        <created by="John Lumley" on="2013-10-01"/>
+        <environment ref="json-to-xml-E"/>
+        <test>
+            <initial-template name="json-to-xml-error-008"/>
+        </test>
+        <result>
+            <error code="XTDE3240"/>
+        </result>
+    </test-case>
+    
+    <test-case name="json-to-xml-error-009">
+        <description>Extra token after array value</description>
+        <created by="John Lumley" on="2013-10-01"/>
+        <environment ref="json-to-xml-E"/>
+        <test>
+            <initial-template name="json-to-xml-error-009"/>
+        </test>
+        <result>
+            <error code="XTDE3240"/>
+        </result>
+    </test-case>
+    
+    <test-case name="json-to-xml-error-010">
+        <description>Leading + on number</description>
+        <created by="John Lumley" on="2013-10-01"/>
+        <environment ref="json-to-xml-E"/>
+        <test>
+            <initial-template name="json-to-xml-error-010"/>
+        </test>
+        <result>
+            <error code="XTDE3240"/>
+        </result>
+    </test-case>
+    
+    <test-case name="json-to-xml-error-011">
+        <description>Redundant leading 0 on number</description>
+        <created by="John Lumley" on="2013-10-01"/>
+        <environment ref="json-to-xml-E"/>
+        <test>
+            <initial-template name="json-to-xml-error-011"/>
+        </test>
+        <result>
+            <error code="XTDE3240"/>
+        </result>
+    </test-case>
+    
+    <test-case name="json-to-xml-error-012">
+        <description>Hex number</description>
+        <created by="John Lumley" on="2013-10-01"/>
+        <environment ref="json-to-xml-E"/>
+        <test>
+            <initial-template name="json-to-xml-error-012"/>
+        </test>
+        <result>
+            <error code="XTDE3240"/>
+        </result>
+    </test-case>
+    
+    <test-case name="json-to-xml-error-013">
+        <description>Trailing backslash</description>
+        <created by="John Lumley" on="2013-10-01"/>
+        <environment ref="json-to-xml-E"/>
+        <test>
+            <initial-template name="json-to-xml-error-013"/>
+        </test>
+        <result>
+            <error code="XTDE3240"/>
+        </result>
+    </test-case>
+    
+    <test-case name="json-to-xml-error-014">
+        <description>Short unicode</description>
+        <created by="John Lumley" on="2013-10-01"/>
+        <environment ref="json-to-xml-E"/>
+        <test>
+            <initial-template name="json-to-xml-error-014"/>
+        </test>
+        <result>
+            <error code="XTDE3240"/>
+        </result>
+    </test-case>
+    
+    <test-case name="json-to-xml-error-015">
+        <description>Short unicode</description>
+        <created by="John Lumley" on="2013-10-01"/>
+        <environment ref="json-to-xml-E"/>
+        <test>
+            <initial-template name="json-to-xml-error-015"/>
+        </test>
+        <result>
+            <error code="XTDE3240"/>
+        </result>
+    </test-case>
+    
+    <test-case name="json-to-xml-error-016">
+        <description>Trailing comma in object</description>
+        <created by="John Lumley" on="2013-10-01"/>
+        <environment ref="json-to-xml-E"/>
+        <test>
+            <initial-template name="json-to-xml-error-016"/>
+        </test>
+        <result>
+            <error code="XTDE3240"/>
+        </result>
+    </test-case>
+    
+    <test-case name="json-to-xml-error-017">
+        <description>Trailing comma in object - liberal spec</description>
+        <created by="John Lumley" on="2013-10-01"/>
+        <environment ref="json-to-xml-E"/>
+        <test>
+            <initial-template name="json-to-xml-error-017"/>
+        </test>
+        <result>
+            <any-of>
+                <error code="XTDE3240"/>
+                <assert>/*</assert>
+            </any-of>
+        </result>
+    </test-case>
+    
+    <test-case name="json-to-xml-error-018">
+        <description>Trailing comma in array</description>
+        <created by="John Lumley" on="2013-10-01"/>
+        <environment ref="json-to-xml-E"/>
+        <test>
+            <initial-template name="json-to-xml-error-018"/>
+        </test>
+        <result>
+            <error code="XTDE3240"/>
+        </result>
+    </test-case>
+    
+    <test-case name="json-to-xml-error-019">
+        <description>Trailing comma in array - liberal spec</description>
+        <created by="John Lumley" on="2013-10-01"/>
+        <environment ref="json-to-xml-E"/>
+        <test>
+            <initial-template name="json-to-xml-error-019"/>
+        </test>
+        <result>
+            <any-of>
+                <error code="XTDE3240"/>
+                <assert>/*</assert>
+            </any-of>
+        </result>
+    </test-case>
+    
+    <test-case name="json-to-xml-error-020">
+        <description>Spec option error</description>
+        <created by="John Lumley" on="2013-10-01"/>
+        <environment ref="json-to-xml-E"/>
+        <test>
+            <initial-template name="json-to-xml-error-020"/>
+        </test>
+        <result>
+            <error code="XTDE3260"/>
+        </result>
+    </test-case>
+    
+    <test-case name="json-to-xml-error-021">
+        <description>Spec option error</description>
+        <created by="John Lumley" on="2013-10-01"/>
+        <environment ref="json-to-xml-E"/>
+        <test>
+            <initial-template name="json-to-xml-error-021"/>
+        </test>
+        <result>
+            <error code="XTDE3260"/>
+        </result>
+    </test-case>
+    
+    <test-case name="json-to-xml-error-022">
+        <description>Validate option error</description>
+        <created by="John Lumley" on="2013-10-01"/>
+        <environment ref="json-to-xml-E"/>
+        <test>
+            <initial-template name="json-to-xml-error-022"/>
+        </test>
+        <result>
+            <error code="XTDE3260"/>
+        </result>
+    </test-case>
+    
+    <test-case name="json-to-xml-error-023">
+        <description>Validate option error</description>
+        <created by="John Lumley" on="2013-10-01"/>
+        <environment ref="json-to-xml-E"/>
+        <test>
+            <initial-template name="json-to-xml-error-023"/>
+        </test>
+        <result>
+            <error code="XTDE3260"/>
+        </result>
+    </test-case>
+    
+    <test-case name="json-to-xml-error-024">
+        <description>Validate option error</description>
+        <created by="John Lumley" on="2013-10-01"/>
+        <environment ref="json-to-xml-E"/>
+        <test>
+            <initial-template name="json-to-xml-error-024"/>
+        </test>
+        <result>
+            <error code="XTDE3260"/>
+        </result>
+    </test-case>
+    
+    <test-case name="json-to-xml-error-025">
+        <description>Unescape option error</description>
+        <created by="John Lumley" on="2013-10-01"/>
+        <environment ref="json-to-xml-E"/>
+        <test>
+            <initial-template name="json-to-xml-error-025"/>
+        </test>
+        <result>
+            <error code="XTDE3260"/>
+        </result>
+    </test-case>
+    
+    <test-case name="json-to-xml-error-026">
+        <description>Unescape option error</description>
+        <created by="John Lumley" on="2013-10-01"/>
+        <environment ref="json-to-xml-E"/>
+        <test>
+            <initial-template name="json-to-xml-error-026"/>
+        </test>
+        <result>
+            <error code="XTDE3260"/>
+        </result>
+    </test-case>
+    
+    <test-case name="json-to-xml-error-027">
+        <description>Unescape option error</description>
+        <created by="John Lumley" on="2013-10-01"/>
+        <environment ref="json-to-xml-E"/>
+        <test>
+            <initial-template name="json-to-xml-error-027"/>
+        </test>
+        <result>
+            <error code="XTDE3260"/>
+        </result>
+    </test-case>
+    
+    <test-case name="json-to-xml-error-028">
+        <description>Fallback option not function </description>
+        <created by="John Lumley" on="2013-10-01"/>
+        <environment ref="json-to-xml-E"/>
+        <test>
+            <initial-template name="json-to-xml-error-028"/>
+        </test>
+        <result>
+            <error code="XTDE3260"/>
+        </result>
+    </test-case>
+
+</test-set>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fn/json-to-xml/data001.json	Wed Jul 23 17:02:10 2014 +0200
@@ -0,0 +1,22 @@
+{
+    "glossary": {
+        "title": "example glossary",
+		"GlossDiv": {
+            "title": "S",
+			"GlossList": {
+                "GlossEntry": {
+                    "ID": "SGML",
+					"SortAs": "SGML",
+					"GlossTerm": "Standard Generalized Markup Language",
+					"Acronym": "SGML",
+					"Abbrev": "ISO 8879:1986",
+					"GlossDef": {
+                        "para": "A meta-markup language, used to create markup languages such as DocBook.",
+						"GlossSeeAlso": ["GML", "XML"]
+                    },
+					"GlossSee": "markup"
+                }
+            }
+        }
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fn/json-to-xml/data005.json	Wed Jul 23 17:02:10 2014 +0200
@@ -0,0 +1,27 @@
+{"menu": {
+    "header": "SVG Viewer",
+    "items": [
+        {"id": "Open"},
+        {"id": "OpenNew", "label": "Open New"},
+        null,
+        {"id": "ZoomIn", "label": "Zoom In"},
+        {"id": "ZoomOut", "label": "Zoom Out"},
+        {"id": "OriginalView", "label": "Original View"},
+        null,
+        {"id": "Quality"},
+        {"id": "Pause"},
+        {"id": "Mute"},
+        null,
+        {"id": "Find", "label": "Find..."},
+        {"id": "FindAgain", "label": "Find Again"},
+        {"id": "Copy"},
+        {"id": "CopyAgain", "label": "Copy Again"},
+        {"id": "CopySVG", "label": "Copy SVG"},
+        {"id": "ViewSVG", "label": "View SVG"},
+        {"id": "ViewSource", "label": "View Source"},
+        {"id": "SaveAs", "label": "Save As"},
+        null,
+        {"id": "Help"},
+        {"id": "About", "label": "About Adobe CVG Viewer..."}
+    ]
+}}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fn/json-to-xml/escapeText.json	Wed Jul 23 17:02:10 2014 +0200
@@ -0,0 +1,3 @@
+{
+    "key" : "Data with \" within it"
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fn/json-to-xml/json-to-xml-A.xsl	Wed Jul 23 17:02:10 2014 +0200
@@ -0,0 +1,198 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+    <xsl:param name="options.escape" select="map{'unescape':false()}"/>
+    <xsl:param name="options.validate" select="map{'validate':true()}"/>
+    
+    <xsl:param name="options.rfc" select="map{'spec':'RFC4627'}"/>
+    <xsl:param name="options.ecma" select="map{'spec':'ECMA-262'}"/>
+    
+    <xsl:param name="s0.map" select="'{}'"/>
+    <xsl:param name="s0.array" select="'[]'"/>
+    <xsl:param name="s1.number" select="'[1]'"/>
+    <xsl:param name="s1.string" select="'[&#34;a&#34;]'"/>
+    <xsl:param name="s1.true" select="'[true]'"/>
+    <xsl:param name="s1.false" select="'[false]'"/>
+    <xsl:param name="s1.null" select="'[null]'"/>
+    
+    
+    <xsl:param name="s2" select="'{&#34;x&#34;:1, &#34;y&#34;:[1,2,3]}'"/>
+    
+    <xsl:param name="escape.1" select="'[&#34;Data with \&#34; within it&#34;]'"/>
+    <xsl:param name="escape.2"
+        select="'{&#34;Key \&#34; with quote&#34;:&#34;Data with \&#34; within it&#34;}'"/>
+    
+    <xsl:template name="json-to-xml-001">
+        <xsl:variable name="metadata">
+            <description>Empty object as document-node</description>
+            <created by="John Lumley" on="2013-10-01"/>
+            <environment ref="JSON-XML"/>
+        </xsl:variable>
+        <xsl:copy-of select=" json-to-xml($s0.map) "/>
+        <xsl:variable name="expected-results">
+            <all-of>
+                <assert-count>1</assert-count>
+                <assert-type>document-node()</assert-type>
+            </all-of>
+        </xsl:variable>
+    </xsl:template>
+    <xsl:template name="json-to-xml-002">
+        <xsl:variable name="metadata">
+            <description>Empty object</description>
+            <created by="John Lumley" on="2013-10-01"/>
+            <environment ref="JSON-XML"/>
+        </xsl:variable>
+        <xsl:copy-of select=" json-to-xml($s0.map) "/>
+        <xsl:variable name="expected-results">
+            <all-of>
+                <assert-count>1</assert-count>
+                <assert-type>element(Q{http://www.w3.org/2013/XSL/json}map)</assert-type>
+                <assert>count($result/*) eq 0</assert>
+            </all-of>
+        </xsl:variable>
+    </xsl:template>
+    <xsl:template name="json-to-xml-003">
+        <xsl:variable name="metadata">
+            <description>Empty array as document-node</description>
+            <created by="John Lumley" on="2013-10-01"/>
+            <environment ref="JSON-XML"/>
+        </xsl:variable>
+        <xsl:copy-of select=" json-to-xml($s0.array) "/>
+        <xsl:variable name="expected-results">
+            <all-of>
+                <assert-count>1</assert-count>
+                <assert-type>document-node()</assert-type>
+            </all-of>
+        </xsl:variable>
+    </xsl:template>
+    <xsl:template name="json-to-xml-004">
+        <xsl:variable name="metadata">
+            <description>Empty array</description>
+            <created by="John Lumley" on="2013-10-01"/>
+            <environment ref="JSON-XML"/>
+        </xsl:variable>
+        <xsl:copy-of select=" json-to-xml($s0.array) "/>
+        <xsl:variable name="expected-results">
+            <all-of>
+                <assert-count>1</assert-count>
+                <assert-type>element(Q{http://www.w3.org/2013/XSL/json}array)</assert-type>
+                <assert>count($result/*) eq 0</assert>
+            </all-of>
+        </xsl:variable>
+    </xsl:template>
+    <xsl:template name="json-to-xml-005">
+        <xsl:variable name="metadata">
+            <description>Array Number</description>
+            <created by="John Lumley" on="2013-10-01"/>
+            <environment ref="JSON-XML"/>
+        </xsl:variable>
+        <xsl:copy-of select=" json-to-xml($s1.number) "/>
+        <xsl:variable name="expected-results">
+            <all-of>
+                <assert-count>1</assert-count>
+                <assert-type>element(Q{http://www.w3.org/2013/XSL/json}array)</assert-type>
+                <assert>count($result/*) eq 1</assert>
+                <assert>$result/*[1] instance of element(j:number,xs:untyped)</assert>
+                <assert>xs:double($result/*[1]) eq 1</assert>
+            </all-of>
+        </xsl:variable>
+    </xsl:template>
+    <xsl:template name="json-to-xml-006">
+        <xsl:variable name="metadata">
+            <description>Array String</description>
+            <created by="John Lumley" on="2013-10-01"/>
+            <environment ref="JSON-XML"/>
+        </xsl:variable>
+        <xsl:copy-of select=" json-to-xml($s1.string) "/>
+        <xsl:variable name="expected-results">
+            <all-of>
+                <assert-count>1</assert-count>
+                <assert-type>element(*)</assert-type>
+                <assert>count($result/*) eq 1</assert>
+                <assert>$result/*[1] instance of element(j:string,xs:untyped)</assert>
+                <assert>xs:string($result/*[1]) eq "a"</assert>
+            </all-of>
+        </xsl:variable>
+    </xsl:template>
+    <xsl:template name="json-to-xml-007">
+        <xsl:variable name="metadata">
+            <description>Array True</description>
+            <created by="John Lumley" on="2013-10-01"/>
+            <environment ref="JSON-XML"/>
+        </xsl:variable>
+        <xsl:copy-of select=" json-to-xml($s1.true) "/>
+        <xsl:variable name="expected-results">
+            <all-of>
+                <assert-count>1</assert-count>
+                <assert-type>element(*)</assert-type>
+                <assert>count($result/*) eq 1</assert>
+                <assert>$result/*[1] instance of element(j:boolean,xs:untyped)</assert>
+                <assert>xs:boolean($result/*[1]) eq true()</assert>
+            </all-of>
+        </xsl:variable>
+    </xsl:template>
+    <xsl:template name="json-to-xml-008">
+        <xsl:variable name="metadata">
+            <description>Array False</description>
+            <created by="John Lumley" on="2013-10-01"/>
+            <environment ref="JSON-XML"/>
+        </xsl:variable>
+        <xsl:copy-of select=" json-to-xml($s1.false) "/>
+        <xsl:variable name="expected-results">
+            <all-of>
+                <assert-count>1</assert-count>
+                <assert-type>element(*)</assert-type>
+                <assert>count($result/*) eq 1</assert>
+                <assert>$result/*[1] instance of element(j:boolean,xs:untyped)</assert>
+                <assert>xs:boolean($result/*[1]) eq false()</assert>
+            </all-of>
+        </xsl:variable>
+    </xsl:template>
+    <xsl:template name="json-to-xml-009">
+        <xsl:variable name="metadata">
+            <description>Array Null</description>
+            <created by="John Lumley" on="2013-10-01"/>
+            <environment ref="JSON-XML"/>
+        </xsl:variable>
+        <xsl:copy-of select=" json-to-xml($s1.null) "/>
+        <xsl:variable name="expected-results">
+            <all-of>
+                <assert-count>1</assert-count>
+                <assert-type>element(*)</assert-type>
+                <assert>count($result/*) eq 1</assert>
+                <assert>$result/*[1] instance of element(j:null,xs:untyped)</assert>
+                <assert>empty($result/*[1]/(*|text()))</assert>
+            </all-of>
+        </xsl:variable>
+    </xsl:template>
+    <xsl:template name="json-to-xml-010">
+        <xsl:variable name="metadata">
+            <description>Larger 2</description>
+            <created by="John Lumley" on="2013-10-01"/>
+            <environment ref="JSON-XML"/>
+        </xsl:variable>
+        <xsl:copy-of select=" json-to-xml(unparsed-text('data001.json')) "/>
+        <xsl:variable name="expected-results">
+            <all-of>
+                <assert-count>1</assert-count>
+                <assert-type>element(*)</assert-type>
+                <assert>count($result/*) eq 1</assert>
+            </all-of>
+        </xsl:variable>
+    </xsl:template>
+    <xsl:template name="json-to-xml-011">
+        <xsl:variable name="metadata">
+            <description>Larger 2</description>
+            <created by="John Lumley" on="2013-10-01"/>
+            <environment ref="JSON-XML"/>
+        </xsl:variable>
+        <xsl:copy-of select=" json-to-xml(unparsed-text('data005.json')) "/>
+    </xsl:template>
+    <xsl:template name="json-to-xml-012">
+        <xsl:variable name="metadata">
+            <description>Larger 2</description>
+            <created by="John Lumley" on="2013-10-01"/>
+            <environment ref="JSON-XML"/>
+        </xsl:variable>
+        <xsl:copy-of select=" json-to-xml(unparsed-text('escapeText.json')) "/>
+    </xsl:template>
+</xsl:stylesheet>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fn/json-to-xml/json-to-xml-E.xsl	Wed Jul 23 17:02:10 2014 +0200
@@ -0,0 +1,255 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+    <xsl:template name="json-to-xml-error-001">
+        <xsl:variable name="metadata">
+            <description>Empty string</description>
+            <created by="John Lumley" on="2013-10-01"/>
+            <environment ref="JSON-XML"/>
+        </xsl:variable>
+        <xsl:variable name="json" select="''"/>
+        <xsl:copy-of select="json-to-xml($json)"/>
+    </xsl:template>
+    <xsl:template name="json-to-xml-error-002">
+        <xsl:variable name="metadata">
+            <description>Unknown token</description>
+            <created by="John Lumley" on="2013-10-01"/>
+            <environment ref="JSON-XML"/>
+        </xsl:variable>
+        <xsl:variable name="json">{error}</xsl:variable>
+        <xsl:copy-of select="json-to-xml($json)"/>
+    </xsl:template>
+    <xsl:template name="json-to-xml-error-003">
+        <xsl:variable name="metadata">
+            <description>Unknown token</description>
+            <created by="John Lumley" on="2013-10-01"/>
+            <environment ref="JSON-XML"/>
+        </xsl:variable>
+        <xsl:variable name="json">{terriblyWrong}</xsl:variable>
+        <xsl:copy-of select="json-to-xml($json)"/>
+    </xsl:template>
+    <xsl:template name="json-to-xml-error-004">
+        <xsl:variable name="metadata">
+            <description>Extra token</description>
+            <created by="John Lumley" on="2013-10-01"/>
+            <environment ref="JSON-XML"/>
+        </xsl:variable>
+        <xsl:variable name="json">{}"extra token"</xsl:variable>
+        <xsl:copy-of select="json-to-xml($json)"/>
+    </xsl:template>
+    <xsl:template name="json-to-xml-error-005">
+        <xsl:variable name="metadata">
+            <description>Non-string key</description>
+            <created by="John Lumley" on="2013-10-01"/>
+            <environment ref="JSON-XML"/>
+        </xsl:variable>
+        <xsl:variable name="json">{1:1}</xsl:variable>
+        <xsl:copy-of select="json-to-xml($json)"/>
+    </xsl:template>
+    <xsl:template name="json-to-xml-error-006">
+        <xsl:variable name="metadata">
+            <description>Non-string key</description>
+            <created by="John Lumley" on="2013-10-01"/>
+            <environment ref="JSON-XML"/>
+        </xsl:variable>
+        <xsl:variable name="json">{true:1}</xsl:variable>
+        <xsl:copy-of select="json-to-xml($json)"/>
+    </xsl:template>
+    <xsl:template name="json-to-xml-error-007">
+        <xsl:variable name="metadata">
+            <description>Missing colon after key</description>
+            <created by="John Lumley" on="2013-10-01"/>
+            <environment ref="JSON-XML"/>
+        </xsl:variable>
+        <xsl:variable name="json">{"key" 1}</xsl:variable>
+        <xsl:copy-of select="json-to-xml($json)"/>
+    </xsl:template>
+    <xsl:template name="json-to-xml-error-008">
+        <xsl:variable name="metadata">
+            <description>Extra token after map value</description>
+            <created by="John Lumley" on="2013-10-01"/>
+            <environment ref="JSON-XML"/>
+        </xsl:variable>
+        <xsl:variable name="json">{"key":1 2}</xsl:variable>
+        <xsl:copy-of select="json-to-xml($json)"/>
+    </xsl:template>
+    <xsl:template name="json-to-xml-error-009">
+        <xsl:variable name="metadata">
+            <description>Extra token after array value</description>
+            <created by="John Lumley" on="2013-10-01"/>
+            <environment ref="JSON-XML"/>
+        </xsl:variable>
+        <xsl:variable name="json">["key",1 2]</xsl:variable>
+        <xsl:copy-of select="json-to-xml($json)"/>
+    </xsl:template>
+    <xsl:template name="json-to-xml-error-010">
+        <xsl:variable name="metadata">
+            <description>Leading + on number</description>
+            <created by="John Lumley" on="2013-10-01"/>
+            <environment ref="JSON-XML"/>
+        </xsl:variable>
+        <xsl:variable name="json">[+1]</xsl:variable>
+        <xsl:copy-of select="json-to-xml($json)"/>
+    </xsl:template>
+    <xsl:template name="json-to-xml-error-011">
+        <xsl:variable name="metadata">
+            <description>Redundant leading 0 on number</description>
+            <created by="John Lumley" on="2013-10-01"/>
+            <environment ref="JSON-XML"/>
+        </xsl:variable>
+        <xsl:variable name="json">[01]</xsl:variable>
+        <xsl:copy-of select="json-to-xml($json)"/>
+    </xsl:template>
+    <xsl:template name="json-to-xml-error-012">
+        <xsl:variable name="metadata">
+            <description>Hex number</description>
+            <created by="John Lumley" on="2013-10-01"/>
+            <environment ref="JSON-XML"/>
+        </xsl:variable>
+        <xsl:variable name="json">[1234A]</xsl:variable>
+        <xsl:copy-of select="json-to-xml($json)"/>
+    </xsl:template>
+    <xsl:template name="json-to-xml-error-013">
+        <xsl:variable name="metadata">
+            <description>Trailing backslash</description>
+            <created by="John Lumley" on="2013-10-01"/>
+            <environment ref="JSON-XML"/>
+        </xsl:variable>
+        <xsl:variable name="json">["123\"]</xsl:variable>
+        <xsl:copy-of select="json-to-xml($json)"/>
+    </xsl:template>
+    <xsl:template name="json-to-xml-error-014">
+        <xsl:variable name="metadata">
+            <description>Short unicode</description>
+            <created by="John Lumley" on="2013-10-01"/>
+            <environment ref="JSON-XML"/>
+        </xsl:variable>
+        <xsl:variable name="json">["123\u234"]</xsl:variable>
+        <xsl:copy-of select="json-to-xml($json)"/>
+    </xsl:template>
+    <xsl:template name="json-to-xml-error-015">
+        <xsl:variable name="metadata">
+            <description>Unicode null</description>
+            <created by="John Lumley" on="2013-10-01"/>
+            <environment ref="JSON-XML"/>
+        </xsl:variable>
+        <xsl:variable name="json">["String with \u0000 backspace"]</xsl:variable>
+        <xsl:copy-of select="json-to-xml($json)"/>
+    </xsl:template>
+    <xsl:template name="json-to-xml-error-016">
+        <xsl:variable name="metadata">
+            <description>Trailing comma in object</description>
+            <created by="John Lumley" on="2013-10-01"/>
+            <environment ref="JSON-XML"/>
+        </xsl:variable>
+        <xsl:variable name="json">{"key":123,}</xsl:variable>
+        <xsl:copy-of select="json-to-xml($json)"/>
+    </xsl:template>
+    <xsl:template name="json-to-xml-error-017">
+        <xsl:variable name="metadata">
+            <description>Trailing comma in object - liberal spec</description>
+            <created by="John Lumley" on="2013-10-01"/>
+            <environment ref="JSON-XML"/>
+        </xsl:variable>
+        <xsl:variable name="json">{"key":123 ,}</xsl:variable>
+        <xsl:copy-of select="json-to-xml($json,map{'spec':'liberal'})"/>
+    </xsl:template>
+    <xsl:template name="json-to-xml-error-018">
+        <xsl:variable name="metadata">
+            <description>Trailing comma in array</description>
+            <created by="John Lumley" on="2013-10-01"/>
+            <environment ref="JSON-XML"/>
+        </xsl:variable>
+        <xsl:variable name="json">["key",123,]</xsl:variable>
+        <xsl:copy-of select="json-to-xml($json)"/>
+    </xsl:template>
+    <xsl:template name="json-to-xml-error-019">
+        <xsl:variable name="metadata">
+            <description>Trailing comma in array - liberal spec</description>
+            <created by="John Lumley" on="2013-10-01"/>
+            <environment ref="JSON-XML"/>
+        </xsl:variable>
+        <xsl:variable name="json">["key",123,]</xsl:variable>
+        <xsl:copy-of select="json-to-xml($json,map{'spec':'liberal'})"/>
+    </xsl:template>
+    <xsl:template name="json-to-xml-error-020">
+        <xsl:variable name="metadata">
+            <description>Spec option error</description>
+            <created by="John Lumley" on="2013-10-01"/>
+            <environment ref="JSON-XML"/>
+        </xsl:variable>
+        <xsl:variable name="json">["String"]</xsl:variable>
+        <xsl:copy-of select="json-to-xml($json,map{'spec':()})"/>
+    </xsl:template>
+    <xsl:template name="json-to-xml-error-021">
+        <xsl:variable name="metadata">
+            <description>Spec option error</description>
+            <created by="John Lumley" on="2013-10-01"/>
+            <environment ref="JSON-XML"/>
+        </xsl:variable>
+        <xsl:variable name="json">["String"]</xsl:variable>
+        <xsl:copy-of select="json-to-xml($json,map{'spec':('EMCA-262','RFC4627')})"/>
+    </xsl:template>
+    <xsl:template name="json-to-xml-error-022">
+        <xsl:variable name="metadata">
+            <description>Validate option error</description>
+            <created by="John Lumley" on="2013-10-01"/>
+            <environment ref="JSON-XML"/>
+        </xsl:variable>
+        <xsl:variable name="json">["String"]</xsl:variable>
+        <xsl:copy-of select="json-to-xml($json, map{'validate':()})"/>
+    </xsl:template>
+    <xsl:template name="json-to-xml-error-023">
+        <xsl:variable name="metadata">
+            <description>Validate option error</description>
+            <created by="John Lumley" on="2013-10-01"/>
+            <environment ref="JSON-XML"/>
+        </xsl:variable>
+        <xsl:variable name="json">["String"]</xsl:variable>
+        <xsl:copy-of select="json-to-xml($json, map{'validate':(true(),true())})"/>
+    </xsl:template>
+    <xsl:template name="json-to-xml-error-024">
+        <xsl:variable name="metadata">
+            <description>Validate option error</description>
+            <created by="John Lumley" on="2013-10-01"/>
+            <environment ref="JSON-XML"/>
+        </xsl:variable>
+        <xsl:variable name="json">["String"]</xsl:variable>
+        <xsl:copy-of select="json-to-xml($json, map{'validate':'EMCA-262'})"/>
+    </xsl:template>
+    <xsl:template name="json-to-xml-error-025">
+        <xsl:variable name="metadata">
+            <description>Unescape option error</description>
+            <created by="John Lumley" on="2013-10-01"/>
+            <environment ref="JSON-XML"/>
+        </xsl:variable>
+        <xsl:variable name="json">["String"]</xsl:variable>
+        <xsl:copy-of select="json-to-xml($json, map{'unescape':()})"/>
+    </xsl:template>
+    <xsl:template name="json-to-xml-error-026">
+        <xsl:variable name="metadata">
+            <description>Unescape option error</description>
+            <created by="John Lumley" on="2013-10-01"/>
+            <environment ref="JSON-XML"/>
+        </xsl:variable>
+        <xsl:variable name="json">["String"]</xsl:variable>
+        <xsl:copy-of select="json-to-xml($json,map{'unescape':(true(),true())})"/>
+    </xsl:template>
+    <xsl:template name="json-to-xml-error-027">
+        <xsl:variable name="metadata">
+            <description>Unescape option error</description>
+            <created by="John Lumley" on="2013-10-01"/>
+            <environment ref="JSON-XML"/>
+        </xsl:variable>
+        <xsl:variable name="json">["String"]</xsl:variable>
+        <xsl:copy-of select="json-to-xml($json, map{'unescape':'EMCA-262'})"/>
+    </xsl:template>
+    <xsl:template name="json-to-xml-error-028">
+        <xsl:variable name="metadata">
+            <description>Fallback option not function </description>
+            <created by="John Lumley" on="2013-10-01"/>
+            <environment ref="JSON-XML"/>
+        </xsl:variable>
+        <xsl:variable name="json">["String"]</xsl:variable>
+        <xsl:copy-of select="json-to-xml($json,map{'fallback':='dummy'})"/>
+    </xsl:template>
+</xsl:stylesheet>
--- a/tests/fn/key/_key-test-set.xml	Wed Jul 23 16:35:29 2014 +0200
+++ b/tests/fn/key/_key-test-set.xml	Wed Jul 23 17:02:10 2014 +0200
@@ -8,6 +8,7 @@
    <environment name="key101">
       <source role="." file="key101.xml"/>
    </environment>
+
    <environment name="key105">
       <source role="." file="key105.xml"/>
    </environment>
@@ -83,6 +84,11 @@
       </source>
    </environment>
    
+   <environment name="key285">
+      <source role="." file="key101.xml"/>
+      <stylesheet file="key-085.xsl"/>
+   </environment>
+   
 
    <test-case name="key-001">
       <description>Test generate-id() as used in grouping.</description>
@@ -1545,4 +1551,44 @@
          <assert-xml><![CDATA[<o><elem type="a"><active>true</active><dataset><field1>x</field1><field2>x</field2><field3><field4>x</field4><field5>x</field5></field3></dataset></elem></o>]]></assert-xml>
       </result>
    </test-case>
+   
+   <test-case name="key-085a">
+      <description>
+        Test a key whose match pattern depends on a parameter. 
+        See Saxon bug https://saxonica.plan.io/issues/1968
+        This test and key-085b both work when run individually, but in Saxon 9.5 the second
+        test fails because the index is built based on the original value of the parameter, 
+        and is then re-used in the second test.
+      </description>
+      <created by="Michael Kay" on="2014-06-04"/>
+      <environment ref="key285">
+         <source role="." file="key306.xml"/>
+      </environment>
+      <dependencies>
+         <spec value="XSLT20+"/>
+      </dependencies>
+      <test>
+         <param name="min" select="8"/>
+      </test>
+      <result>
+         <assert>/out = "Cambridge Manchester Pittsfield Rochester Springfield"</assert>
+      </result>
+   </test-case>
+   
+   <test-case name="key-085b">
+      <description>Test a key whose match pattern depends on a parameter. See Saxon bug https://saxonica.plan.io/issues/1968</description>
+      <created by="Michael Kay" on="2014-06-04"/>
+      <environment ref="key285">
+         <source role="." file="key306.xml"/>
+      </environment>
+      <dependencies>
+         <spec value="XSLT20+"/>
+      </dependencies>
+      <test>
+         <param name="min" select="2"/>
+      </test>
+      <result>
+         <assert>/out = "Amherst Auburn Cambridge Grafton Hudson Lincoln Manchester Pittsfield Rochester Salem Springfield"</assert>
+      </result>
+   </test-case>
 </test-set>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fn/key/key-085.xsl	Wed Jul 23 17:02:10 2014 +0200
@@ -0,0 +1,18 @@
+<?xml version="1.0"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
+
+  <!-- Purpose: key dependent on value of a parameter. -->
+
+  <xsl:output method="xml" encoding="UTF-8" indent="no"/>
+  
+  <xsl:param name="min" required="yes"/>
+
+  <xsl:key name="places" match="town[string-length(@name) gt $min]" use="@state"/>
+
+  <xsl:template match="doc">
+    <out>
+      <xsl:value-of select="key('places', 'MA')/@name"/>
+    </out>
+  </xsl:template>
+
+</xsl:stylesheet>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fn/stream-available/_stream-available-test-set.xml	Wed Jul 23 17:02:10 2014 +0200
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<test-set xmlns:xs="http://www.w3.org/2001/XMLSchema"
+          xmlns="http://www.w3.org/2012/10/xslt-test-catalog"
+          name="stream-available">
+   <description>Tests stream-available() function in XSLT 3.0</description>
+   
+   <dependencies>
+       <spec value="XSLT30+"/>
+   </dependencies>
+
+   <test-case name="stream-available-001">
+      <description>Returns false if stream not available</description>
+      <created by="Michael Kay" on="2014-07-18"/>      
+      <test>
+         <stylesheet file="stream-available-001.xsl"/>
+         <initial-template name="main"/>
+      </test>
+      <result>
+         <assert>/out = "false"</assert>
+      </result>
+   </test-case>
+
+
+</test-set>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fn/stream-available/stream-available-001.xsl	Wed Jul 23 17:02:10 2014 +0200
@@ -0,0 +1,10 @@
+<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+  xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs">
+
+  <!-- stream-available() on a non-existent stream -->
+  
+  <xsl:template name="main">
+    <out><xsl:value-of select="stream-available('non-existent-stream.xml')"/></out>
+  </xsl:template>
+
+</xsl:stylesheet>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fn/xml-to-json/_xml-to-json-test-set.xml	Wed Jul 23 17:02:10 2014 +0200
@@ -0,0 +1,360 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<test-set xmlns:xs="http://www.w3.org/2001/XMLSchema"
+          xmlns="http://www.w3.org/2012/10/xslt-test-catalog"
+          name="xml-to-json">
+   <description>xml-to-json() function</description>
+   
+   <environment name="xml-to-json-A">
+      <stylesheet file="xml-to-json-A.xsl"/>
+   </environment>
+   
+   <environment name="xml-to-json-B">
+      <stylesheet file="xml-to-json-B.xsl"/>
+   </environment>
+   
+   <dependencies>
+      <spec value="XSLT30+"/>
+   </dependencies>
+   
+   <test-case name="xml-to-json-A001">
+      <description>Test of xml-to-json: simple "null" content</description>
+      <created by="Michael Kay" on="2014-07-19"/>
+      <environment ref="xml-to-json-A"/>
+      <test>
+         <initial-template name="t001"/>
+      </test>
+      <result>
+         <assert>/t001 = "null"</assert>
+      </result>
+   </test-case>
+   
+   <test-case name="xml-to-json-A002">
+      <description>Test of xml-to-json: simple "true" content</description>
+      <created by="Michael Kay" on="2014-07-19"/>
+      <environment ref="xml-to-json-A"/>
+      <test>
+         <initial-template name="t002"/>
+      </test>
+      <result>
+         <assert>/t002 = "true"</assert>
+      </result>
+   </test-case>
+   
+   <test-case name="xml-to-json-A003">
+      <description>Test of xml-to-json: simple "false" content</description>
+      <created by="Michael Kay" on="2014-07-19"/>
+      <environment ref="xml-to-json-A"/>
+      <test>
+         <initial-template name="t003"/>
+      </test>
+      <result>
+         <assert>/t003 = "false"</assert>
+      </result>
+   </test-case>
+   
+   <test-case name="xml-to-json-A004">
+      <description>Test of xml-to-json: simple numeric content</description>
+      <created by="Michael Kay" on="2014-07-19"/>
+      <environment ref="xml-to-json-A"/>
+      <test>
+         <initial-template name="t004"/>
+      </test>
+      <result>
+         <assert>/t004 = '93.7'</assert>
+      </result>
+   </test-case>
+   
+   <test-case name="xml-to-json-A005">
+      <description>Test of xml-to-json: simple string content</description>
+      <created by="Michael Kay" on="2014-07-19"/>
+      <environment ref="xml-to-json-A"/>
+      <test>
+         <initial-template name="t005"/>
+      </test>
+      <result>
+         <assert>/t005 = '"London"'</assert>
+      </result>
+   </test-case>
+   
+   <test-case name="xml-to-json-A006">
+      <description>Test of xml-to-json: empty string content</description>
+      <created by="Michael Kay" on="2014-07-19"/>
+      <environment ref="xml-to-json-A"/>
+      <test>
+         <initial-template name="t006"/>
+      </test>
+      <result>
+         <assert>/t006 = '""'</assert>
+      </result>
+   </test-case>
+   
+   <test-case name="xml-to-json-A007">
+      <description>Test of xml-to-json: empty array</description>
+      <created by="Michael Kay" on="2014-07-19"/>
+      <environment ref="xml-to-json-A"/>
+      <test>
+         <initial-template name="t007"/>
+      </test>
+      <result>
+         <assert>/t007 = '[]'</assert>
+      </result>
+   </test-case>
+   
+   <test-case name="xml-to-json-A008">
+      <description>Test of xml-to-json: singleton array</description>
+      <created by="Michael Kay" on="2014-07-19"/>
+      <environment ref="xml-to-json-A"/>
+      <test>
+         <initial-template name="t008"/>
+      </test>
+      <result>
+         <assert>/t008 = '[34]'</assert>
+      </result>
+   </test-case>
+   
+   <test-case name="xml-to-json-A009">
+      <description>Test of xml-to-json: two-member array</description>
+      <created by="Michael Kay" on="2014-07-19"/>
+      <environment ref="xml-to-json-A"/>
+      <test>
+         <initial-template name="t009"/>
+      </test>
+      <result>
+         <assert>/t009 = '[true,false]'</assert>
+      </result>
+   </test-case>
+   
+   <test-case name="xml-to-json-A010">
+      <description>Test of xml-to-json: 5-member array</description>
+      <created by="Michael Kay" on="2014-07-19"/>
+      <environment ref="xml-to-json-A"/>
+      <test>
+         <initial-template name="t010"/>
+      </test>
+      <result>
+         <assert>/t010 = '["A","B","C","D","E"]'</assert>
+      </result>
+   </test-case>
+   
+   <test-case name="xml-to-json-A011">
+      <description>Test of xml-to-json: empty map</description>
+      <created by="Michael Kay" on="2014-07-19"/>
+      <environment ref="xml-to-json-A"/>
+      <test>
+         <initial-template name="t011"/>
+      </test>
+      <result>
+         <assert>/t011 = '{}'</assert>
+      </result>
+   </test-case>
+   
+   <test-case name="xml-to-json-A012">
+      <description>Test of xml-to-json: single-entry map</description>
+      <created by="Michael Kay" on="2014-07-19"/>
+      <environment ref="xml-to-json-A"/>
+      <test>
+         <initial-template name="t012"/>
+      </test>
+      <result>
+         <assert>/t012 = '{"A":true}'</assert>
+      </result>
+   </test-case>
+   
+   <test-case name="xml-to-json-A013">
+      <description>Test of xml-to-json: five-entry map</description>
+      <created by="Michael Kay" on="2014-07-19"/>
+      <environment ref="xml-to-json-A"/>
+      <test>
+         <initial-template name="t013"/>
+      </test>
+      <result>
+         <assert>/t013 = '{"A":1,"B":2,"C":3,"D":4,"E":5}'</assert>
+         <!-- Note: order not guaranteed! -->
+      </result>
+   </test-case>
+   
+   <test-case name="xml-to-json-A014">
+      <description>Test of xml-to-json: complex map</description>
+      <created by="Michael Kay" on="2014-07-19"/>
+      <environment ref="xml-to-json-A"/>
+      <test>
+         <initial-template name="t014"/>
+      </test>
+      <result>
+         <assert>/t014 = '{"A":[1,2],"B":[true,false],"C":["Paris","London","Berlin"],"D":[1,true,"on"],"E":[null,null]}'</assert>
+         <!-- Note: order not guaranteed! -->
+      </result>
+   </test-case>
+   
+   <test-case name="xml-to-json-B001">
+      <description>Test of xml-to-json: simple "null" content, indented</description>
+      <created by="Michael Kay" on="2014-07-19"/>
+      <environment ref="xml-to-json-B"/>
+      <test>
+         <initial-template name="t001"/>
+      </test>
+      <result>
+         <assert>translate(/t001, ' &#xa;&#x9;&#xd;', '') = "null"</assert>
+      </result>
+   </test-case>
+   
+   <test-case name="xml-to-json-B002">
+      <description>Test of xml-to-json: simple "true" content, indented</description>
+      <created by="Michael Kay" on="2014-07-19"/>
+      <environment ref="xml-to-json-B"/>
+      <test>
+         <initial-template name="t002"/>
+      </test>
+      <result>
+         <assert>translate(/t002, ' &#xa;&#x9;&#xd;', '') = "true"</assert>
+      </result>
+   </test-case>
+   
+   <test-case name="xml-to-json-B003">
+      <description>Test of xml-to-json: simple "false" content, indented</description>
+      <created by="Michael Kay" on="2014-07-19"/>
+      <environment ref="xml-to-json-B"/>
+      <test>
+         <initial-template name="t003"/>
+      </test>
+      <result>
+         <assert>translate(/t003, ' &#xa;&#x9;&#xd;', '') = "false"</assert>
+      </result>
+   </test-case>
+   
+   <test-case name="xml-to-json-B004">
+      <description>Test of xml-to-json: simple numeric content, indented</description>
+      <created by="Michael Kay" on="2014-07-19"/>
+      <environment ref="xml-to-json-B"/>
+      <test>
+         <initial-template name="t004"/>
+      </test>
+      <result>
+         <assert>translate(/t004, ' &#xa;&#x9;&#xd;', '') = '93.7'</assert>
+      </result>
+   </test-case>
+   
+   <test-case name="xml-to-json-B005">
+      <description>Test of xml-to-json: simple string content, indented</description>
+      <created by="Michael Kay" on="2014-07-19"/>
+      <environment ref="xml-to-json-B"/>
+      <test>
+         <initial-template name="t005"/>
+      </test>
+      <result>
+         <assert>translate(/t005, ' &#xa;&#x9;&#xd;', '') = '"London"'</assert>
+      </result>
+   </test-case>
+   
+   <test-case name="xml-to-json-B006">
+      <description>Test of xml-to-json: empty string content, indented</description>
+      <created by="Michael Kay" on="2014-07-19"/>
+      <environment ref="xml-to-json-B"/>
+      <test>
+         <initial-template name="t006"/>
+      </test>
+      <result>
+         <assert>translate(/t006, ' &#xa;&#x9;&#xd;', '') = '""'</assert>
+      </result>
+   </test-case>
+   
+   <test-case name="xml-to-json-B007">
+      <description>Test of xml-to-json: empty array, indented</description>
+      <created by="Michael Kay" on="2014-07-19"/>
+      <environment ref="xml-to-json-B"/>
+      <test>
+         <initial-template name="t007"/>
+      </test>
+      <result>
+         <assert>translate(/t007, ' &#xa;&#x9;&#xd;', '') = '[]'</assert>
+      </result>
+   </test-case>
+   
+   <test-case name="xml-to-json-B008">
+      <description>Test of xml-to-json: singleton array, indented</description>
+      <created by="Michael Kay" on="2014-07-19"/>
+      <environment ref="xml-to-json-B"/>
+      <test>
+         <initial-template name="t008"/>
+      </test>
+      <result>
+         <assert>translate(/t008, ' &#xa;&#x9;&#xd;', '') = '[34]'</assert>
+      </result>
+   </test-case>
+   
+   <test-case name="xml-to-json-B009">
+      <description>Test of xml-to-json: two-member array, indented</description>
+      <created by="Michael Kay" on="2014-07-19"/>
+      <environment ref="xml-to-json-B"/>
+      <test>
+         <initial-template name="t009"/>
+      </test>
+      <result>
+         <assert>translate(/t009, ' &#xa;&#x9;&#xd;', '') = '[true,false]'</assert>
+      </result>
+   </test-case>
+   
+   <test-case name="xml-to-json-B010">
+      <description>Test of xml-to-json: 5-member array, indented</description>
+      <created by="Michael Kay" on="2014-07-19"/>
+      <environment ref="xml-to-json-B"/>
+      <test>
+         <initial-template name="t010"/>
+      </test>
+      <result>
+         <assert>translate(/t010, ' &#xa;&#x9;&#xd;', '') = '["A","B","C","D","E"]'</assert>
+      </result>
+   </test-case>
+   
+   <test-case name="xml-to-json-B011">
+      <description>Test of xml-to-json: empty map, indented</description>
+      <created by="Michael Kay" on="2014-07-19"/>
+      <environment ref="xml-to-json-B"/>
+      <test>
+         <initial-template name="t011"/>
+      </test>
+      <result>
+         <assert>translate(/t011, ' &#xa;&#x9;&#xd;', '') = '{}'</assert>
+      </result>
+   </test-case>
+   
+   <test-case name="xml-to-json-B012">
+      <description>Test of xml-to-json: single-entry map, indented</description>
+      <created by="Michael Kay" on="2014-07-19"/>
+      <environment ref="xml-to-json-B"/>
+      <test>
+         <initial-template name="t012"/>
+      </test>
+      <result>
+         <assert>translate(/t012, ' &#xa;&#x9;&#xd;', '') = '{"A":true}'</assert>
+      </result>
+   </test-case>
+   
+   <test-case name="xml-to-json-B013">
+      <description>Test of xml-to-json: five-entry map, indented</description>
+      <created by="Michael Kay" on="2014-07-19"/>
+      <environment ref="xml-to-json-B"/>
+      <test>
+         <initial-template name="t013"/>
+      </test>
+      <result>
+         <assert>translate(/t013, ' &#xa;&#x9;&#xd;', '') = '{"A":1,"B":2,"C":3,"D":4,"E":5}'</assert>
+         <!-- Note: order not guaranteed! -->
+      </result>
+   </test-case>
+   
+   <test-case name="xml-to-json-B014">
+      <description>Test of xml-to-json: complex map, indented</description>
+      <created by="Michael Kay" on="2014-07-19"/>
+      <environment ref="xml-to-json-B"/>
+      <test>
+         <initial-template name="t014"/>
+      </test>
+      <result>
+         <assert>translate(/t014, ' &#xa;&#x9;&#xd;', '') = '{"A":[1,2],"B":[true,false],"C":["Paris","London","Berlin"],"D":[1,true,"on"],"E":[null,null]}'</assert>
+         <!-- Note: order not guaranteed! -->
+      </result>
+   </test-case>  
+
+ 
+</test-set>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fn/xml-to-json/xml-to-json-A.xsl	Wed Jul 23 17:02:10 2014 +0200
@@ -0,0 +1,99 @@
+<?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:j="http://www.w3.org/2013/XSL/json"
+    exclude-result-prefixes="xs j"
+    version="3.0">
+    
+    
+    <xsl:output method="xml"/>
+ 
+    
+    <xsl:template name="t001">
+        <t001><xsl:sequence select="xml-to-json(json-to-xml('null'))"/></t001>
+    </xsl:template>
+    
+    <xsl:template name="t002">
+        <t002><xsl:sequence select="xml-to-json(json-to-xml('true'))"/></t002>
+    </xsl:template>
+    
+    <xsl:template name="t003">
+        <t003><xsl:sequence select="xml-to-json(json-to-xml('false'))"/></t003>
+    </xsl:template>
+    
+    <xsl:template name="t004">
+        <t004><xsl:sequence select="xml-to-json(json-to-xml('93.7'))"/></t004>
+    </xsl:template>
+    
+    <xsl:template name="t005">
+        <xsl:variable name="in">"London"</xsl:variable>
+        <t005><xsl:sequence select="xml-to-json(json-to-xml($in))"/></t005>
+    </xsl:template>
+    
+    <xsl:template name="t006">
+        <xsl:variable name="in">""</xsl:variable>
+        <t006><xsl:sequence select="xml-to-json(json-to-xml($in))"/></t006>
+    </xsl:template>
+    
+    <xsl:template name="t007">
+        <xsl:variable name="in">[]</xsl:variable>
+        <t007><xsl:sequence select="xml-to-json(json-to-xml($in))"/></t007>
+    </xsl:template>
+    
+    <xsl:template name="t008">
+        <xsl:variable name="in">[34]</xsl:variable>
+        <t008><xsl:sequence select="xml-to-json(json-to-xml($in))"/></t008>
+    </xsl:template>
+    
+    <xsl:template name="t009">
+        <xsl:variable name="in">[true, false]</xsl:variable>
+        <t009><xsl:sequence select="xml-to-json(json-to-xml($in))"/></t009>
+    </xsl:template>
+    
+    <xsl:template name="t010">
+        <xsl:variable name="in">["A", "B", "C", "D", "E"]</xsl:variable>
+        <t010><xsl:sequence select="xml-to-json(json-to-xml($in))"/></t010>
+    </xsl:template>
+    
+    <xsl:template name="t011">
+        <xsl:variable name="in">{}</xsl:variable>
+        <t011><xsl:sequence select="xml-to-json(json-to-xml($in))"/></t011>
+    </xsl:template>
+    
+    <xsl:template name="t012">
+        <xsl:variable name="in">{"A":true}</xsl:variable>
+        <t012><xsl:sequence select="xml-to-json(json-to-xml($in))"/></t012>
+    </xsl:template>
+    
+    <xsl:template name="t013">
+        <xsl:variable name="in">{"A":1, "B":2, "C":3, "D":4, "E":5}</xsl:variable>
+        <t013><xsl:sequence select="xml-to-json(json-to-xml($in))"/></t013>
+    </xsl:template>
+    
+    <xsl:template name="t014">
+        <xsl:variable name="in">{"A":[1,2], "B":[true,false], "C":["Paris","London","Berlin"], "D":[1, true, "on"], "E":[null, null]}</xsl:variable>
+        <t014><xsl:sequence select="xml-to-json(json-to-xml($in))"/></t014>
+    </xsl:template>
+    
+  
+    <xsl:template name="e001">
+        <xsl:variable name="in">"\\\/\"\r\t\n\u0020"</xsl:variable>
+        <e001><xsl:sequence select="xml-to-json(json-to-xml($in)/*)"/></e001>
+    </xsl:template>
+    
+    <xsl:template name="f001">
+        <xsl:variable name="in" as="element()">
+            <a><b/></a>
+        </xsl:variable>
+        <xsl:variable name="output" as="element()">
+            <output:serialization-parameters xmlns:output="http://www.w3.org/2010/xslt-xquery-serialization">
+                <output:cdata-section-elements value="f001"/>
+                <output:omit-xml-declaration value="yes"/>
+            </output:serialization-parameters>
+        </xsl:variable>
+        <f001><xsl:sequence select="xml-to-json($in, map{ 'fallback' : serialize(?, $output) })"/></f001>
+    </xsl:template>
+    
+    
+    
+</xsl:stylesheet>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fn/xml-to-json/xml-to-json-B.xsl	Wed Jul 23 17:02:10 2014 +0200
@@ -0,0 +1,82 @@
+<?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:j="http://www.w3.org/2013/XSL/json"
+    exclude-result-prefixes="xs j"
+    version="3.0">
+    
+    
+    <xsl:output method="xml" indent="no"/>
+    
+    <xsl:variable name="indent" select="map{ 'indent':true() }"/>
+ 
+    
+    <xsl:template name="t001">
+        <t001><xsl:sequence select="xml-to-json(json-to-xml('null'), $indent)"/></t001>
+    </xsl:template>
+    
+    <xsl:template name="t002">
+        <t002><xsl:sequence select="xml-to-json(json-to-xml('true'), $indent)"/></t002>
+    </xsl:template>
+    
+    <xsl:template name="t003">
+        <t003><xsl:sequence select="xml-to-json(json-to-xml('false'), $indent)"/></t003>
+    </xsl:template>
+    
+    <xsl:template name="t004">
+        <t004><xsl:sequence select="xml-to-json(json-to-xml('93.7'), $indent)"/></t004>
+    </xsl:template>
+    
+    <xsl:template name="t005">
+        <xsl:variable name="in">"London"</xsl:variable>
+        <t005><xsl:sequence select="xml-to-json(json-to-xml($in), $indent)"/></t005>
+    </xsl:template>
+    
+    <xsl:template name="t006">
+        <xsl:variable name="in">""</xsl:variable>
+        <t006><xsl:sequence select="xml-to-json(json-to-xml($in), $indent)"/></t006>
+    </xsl:template>
+    
+    <xsl:template name="t007">
+        <xsl:variable name="in">[]</xsl:variable>
+        <t007><xsl:sequence select="xml-to-json(json-to-xml($in), $indent)"/></t007>
+    </xsl:template>
+    
+    <xsl:template name="t008">
+        <xsl:variable name="in">[34]</xsl:variable>
+        <t008><xsl:sequence select="xml-to-json(json-to-xml($in), $indent)"/></t008>
+    </xsl:template>
+    
+    <xsl:template name="t009">
+        <xsl:variable name="in">[true, false]</xsl:variable>
+        <t009><xsl:sequence select="xml-to-json(json-to-xml($in), $indent)"/></t009>
+    </xsl:template>
+    
+    <xsl:template name="t010">
+        <xsl:variable name="in">["A", "B", "C", "D", "E"]</xsl:variable>
+        <t010><xsl:sequence select="xml-to-json(json-to-xml($in), $indent)"/></t010>
+    </xsl:template>
+    
+    <xsl:template name="t011">
+        <xsl:variable name="in">{}</xsl:variable>
+        <t011><xsl:sequence select="xml-to-json(json-to-xml($in), $indent)"/></t011>
+    </xsl:template>
+    
+    <xsl:template name="t012">
+        <xsl:variable name="in">{"A":true}</xsl:variable>
+        <t012><xsl:sequence select="xml-to-json(json-to-xml($in), $indent)"/></t012>
+    </xsl:template>
+    
+    <xsl:template name="t013">
+        <xsl:variable name="in">{"A":1, "B":2, "C":3, "D":4, "E":5}</xsl:variable>
+        <t013><xsl:sequence select="xml-to-json(json-to-xml($in), $indent)"/></t013>
+    </xsl:template>
+    
+    <xsl:template name="t014">
+        <xsl:variable name="in">{"A":[1,2], "B":[true,false], "C":["Paris","London","Berlin"], "D":[1, true, "on"], "E":[null, null]}</xsl:variable>
+        <t014><xsl:sequence select="xml-to-json(json-to-xml($in), $indent)"/></t014>
+    </xsl:template>
+    
+  
+    
+</xsl:stylesheet>
\ No newline at end of file
--- a/tests/insn/iterate/_iterate-test-set.xml	Wed Jul 23 16:35:29 2014 +0200
+++ b/tests/insn/iterate/_iterate-test-set.xml	Wed Jul 23 17:02:10 2014 +0200
@@ -513,6 +513,18 @@
       </result>
    </test-case>
    
+   <test-case name="iterate-033">
+      <description>Initial value of parameter is an empty sequence</description>
+      <created by="Michael Kay" on="2015-07-01"/>
+      <test>
+         <stylesheet file="iterate-033.xsl"/>
+         <initial-template name="main"/>
+      </test>
+      <result>
+         <assert-xml><![CDATA[<out><ok/><ok/></out>]]></assert-xml>
+      </result>
+   </test-case>
+   
    <test-case name="iterate-901">
       <description>Basic Test of xsl:iterate instruction. Error, xsl:param must come first</description>
       <created by="Michael Kay" on="2012-11-07"/>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/insn/iterate/iterate-033.xsl	Wed Jul 23 17:02:10 2014 +0200
@@ -0,0 +1,32 @@
+<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+  xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs">
+
+  <!-- xsl:iterate; initial value of parameter is an empty sequence -->
+  <!-- Saxon 9.5 bug report from David Rudel -->
+
+  <xsl:variable name="v">
+    <a>
+       <session assignment="A"/>
+       <session assignment="B"/>
+    </a>
+  </xsl:variable>
+
+  <xsl:template name="main">
+    <out>
+       <xsl:iterate select="$v//session">
+          <xsl:param name="assignment" as="xs:string?"/>
+          <xsl:choose>
+             <xsl:when test="not(@assignment eq $assignment)">
+                <ok/>
+                <xsl:next-iteration>
+                   <xsl:with-param name="assignment" select="@assignment"/>
+                </xsl:next-iteration>
+             </xsl:when>
+             <xsl:otherwise>
+               <fail/>
+             </xsl:otherwise>  
+          </xsl:choose>
+       </xsl:iterate>
+     </out>          
+   </xsl:template>
+</xsl:stylesheet>
--- a/tests/strm/sf-avg/_sf-avg-test-set.xml	Wed Jul 23 16:35:29 2014 +0200
+++ b/tests/strm/sf-avg/_sf-avg-test-set.xml	Wed Jul 23 17:02:10 2014 +0200
@@ -279,7 +279,7 @@
    </test-case>
    
    <test-case name="sf-avg-023">
-      <description>avg() using root-select expr /x/y </description>
+      <description>Test of xsl:stream calling avg() using striding select expr with grounding mapping operator of the form /x/y!z</description>
       <keywords>fn:root leading-lone-slash xs:NMTOKENS SimpleMapExpr</keywords>
       <link section-number="19.8.8"/>
       <link section-number="19.8.8.15"/>
--- a/tests/strm/sf-avg/sf-avg-A.xsl	Wed Jul 23 16:35:29 2014 +0200
+++ b/tests/strm/sf-avg/sf-avg-A.xsl	Wed Jul 23 17:02:10 2014 +0200
@@ -202,8 +202,7 @@
       </xsl:stream>
     </xsl:template>
     
-    <!-- Test of xsl:stream calling avg() using //x/y -->
-    <!-- Saxon makes this streamable by rewriting //X/Y as .//Y[parent::X] -->
+    <!-- Test of xsl:stream calling avg() using striding select expr with grounding mapping operator of the form /x/y!z -->
     
     <xsl:template name="s-023" use-when="$RUN">
       <xsl:stream href="../docs/books.xml">
@@ -233,7 +232,7 @@
       </xsl:stream>
     </xsl:template>
     
-    <!-- Streaming avg(): crawling operand, selects nothing -->
+    <!-- Streaming avg(): rooted striding operand, selects nothing -->
     
     <xsl:template name="s-042" use-when="$RUN">
       <xsl:stream href="../docs/books.xml">
--- a/tests/strm/sf-boolean/sf-boolean-001.xsl	Wed Jul 23 16:35:29 2014 +0200
+++ b/tests/strm/sf-boolean/sf-boolean-001.xsl	Wed Jul 23 17:02:10 2014 +0200
@@ -87,7 +87,7 @@
       </xsl:stream>
     </xsl:template> 
     
-    <!-- boolean() with a striding(?) union -->
+    <!-- boolean() with a crawling (striding | striding => crawling) union -->
     
     <xsl:template name="c-009" use-when="$RUN">
       <xsl:stream href="../docs/books.xml">
@@ -236,7 +236,6 @@
     <!-- boolean() on an xs:anyURI -->
     
     <xsl:template name="c-104" use-when="$RUN">
-      <xsl:variable name="b" select="current-date() gt xs:date('1900-01-01')"/>
       <xsl:stream href="../docs/big-transactions.xml">
         <out>
           <xsl:value-of select="boolean(account/transaction[1]/base-uri(.))"/>
--- a/tests/strm/sf-count/_sf-count-test-set.xml	Wed Jul 23 16:35:29 2014 +0200
+++ b/tests/strm/sf-count/_sf-count-test-set.xml	Wed Jul 23 17:02:10 2014 +0200
@@ -65,12 +65,13 @@
    <test-case name="sf-count-005">
       <description>Test of xsl:stream instruction with count(), applied to attributes of ancestor nodes</description>
       <created by="Michael Kay" on="2013-11-18"/>
+      <modified by="Michael Kay" on="2014-06-29" change="correct expected results"/>
       <environment ref="sf-count-A"/>
       <test>
          <initial-template name="c-005"/>
       </test>
       <result>
-         <assert-xml><![CDATA[<out>1</out>]]></assert-xml>
+         <assert>/out = '2'</assert>
       </result>
    </test-case>
    
--- a/tests/strm/sf-unordered/_sf-unordered-test-set.xml	Wed Jul 23 16:35:29 2014 +0200
+++ b/tests/strm/sf-unordered/_sf-unordered-test-set.xml	Wed Jul 23 17:02:10 2014 +0200
@@ -213,7 +213,12 @@
          <initial-template name="r-030"/>
       </test>
       <result>
-         <assert>/out = "????"</assert>
+         <all-of>
+           <assert>/out/tokenize(., " ") = "BOOKLIST"</assert>
+           <assert>/out/tokenize(., " ") = "BOOKS"</assert>
+           <assert>/out/tokenize(., " ") = "ITEM"</assert>
+           <assert>count(/out/tokenize(., " ")) = 3</assert>
+         </all-of>
       </result>
    </test-case>
    
@@ -225,7 +230,12 @@
          <initial-template name="r-031"/>
       </test>
       <result>
-         <assert>/out = "????"</assert>
+         <all-of>
+           <assert>/out/tokenize(., " ") = "BOOKLIST"</assert>
+           <assert>/out/tokenize(., " ") = "BOOKS"</assert>
+           <assert>/out/tokenize(., " ") = "ITEM"</assert>
+           <assert>count(/out/tokenize(., " ")) = 8</assert>
+         </all-of>
       </result>
    </test-case> 
    
@@ -237,7 +247,10 @@
          <initial-template name="r-032"/>
       </test>
       <result>
-         <assert>/out = "????"</assert>
+         <any-of>
+           <assert>/out = "MHK|MMP"</assert>
+           <assert>/out = "MMP|MHK"</assert>
+         </any-of>  
       </result>
    </test-case>
    
@@ -249,7 +262,12 @@
          <initial-template name="r-033"/>
       </test>
       <result>
-         <assert>/out = "????"</assert>
+         <all-of>
+           <assert>/out/tokenize(., "\|") = "MMP"</assert>
+           <assert>/out/tokenize(., "\|") = "P"</assert>
+           <assert>/out/tokenize(., "\|") = "H"</assert>
+           <assert>count(/out/tokenize(., "\|")) = 6</assert>
+         </all-of>
       </result>
    </test-case> 
    
@@ -261,7 +279,12 @@
          <initial-template name="r-034"/>
       </test>
       <result>
-         <assert>/out = "????"</assert>
+         <all-of>
+           <assert>/out/tokenize(., "\|") = "MMP"</assert>
+           <assert>/out/tokenize(., "\|") = "P"</assert>
+           <assert>/out/tokenize(., "\|") = "H"</assert>
+           <assert>count(/out/tokenize(., "\|")) = 6</assert>
+         </all-of>
       </result>
    </test-case>
    
@@ -273,7 +296,13 @@
          <initial-template name="r-035"/>
       </test>
       <result>
-         <assert>/out = "????"</assert>
+         <all-of>
+           <assert>/out/tokenize(., "\|") = "MMP"</assert>
+           <assert>/out/tokenize(., "\|") = "MHK"</assert>
+           <assert>/out/tokenize(., "\|") = "P"</assert>
+           <assert>/out/tokenize(., "\|") = "H"</assert>
+           <assert>count(/out/tokenize(., "\|")) = 7</assert>
+         </all-of>
       </result>
    </test-case>  
 
--- a/tests/strm/si-apply-imports/si-apply-imports-068.xsl	Wed Jul 23 16:35:29 2014 +0200
+++ b/tests/strm/si-apply-imports/si-apply-imports-068.xsl	Wed Jul 23 17:02:10 2014 +0200
@@ -21,13 +21,13 @@
   </xsl:template>
   
   <xsl:template match="/">
-      <xsl:apply-templates select=".//book">
+      <xsl:apply-templates select="outermost(.//book)">
         <xsl:with-param name="q" select="23" tunnel="yes"/> 
       </xsl:apply-templates>
   </xsl:template>
   
   <xsl:template match="bookcoll | tstmt | book">
-    <xsl:apply-templates select=".//bktshort"/>
+    <xsl:apply-templates select="outermost(.//bktshort)"/>
   </xsl:template>
   
   <xsl:template match="bktshort">
--- a/tests/strm/si-apply-imports/si-apply-imports-069.xsl	Wed Jul 23 16:35:29 2014 +0200
+++ b/tests/strm/si-apply-imports/si-apply-imports-069.xsl	Wed Jul 23 17:02:10 2014 +0200
@@ -23,13 +23,13 @@
   </xsl:template>
   
   <xsl:template match="/">
-      <xsl:apply-templates select=".//book">
+      <xsl:apply-templates select="outermost(.//book)">
         <xsl:with-param name="q" select="23" tunnel="yes"/> 
       </xsl:apply-templates>
   </xsl:template>
   
   <xsl:template match="bookcoll | tstmt | book">
-    <xsl:apply-templates select=".//bktshort"/>
+    <xsl:apply-templates select="outermost(.//bktshort)"/>
   </xsl:template>
   
   <xsl:template match="bktshort">
--- a/tests/strm/si-apply-imports/si-apply-imports-070.xsl	Wed Jul 23 16:35:29 2014 +0200
+++ b/tests/strm/si-apply-imports/si-apply-imports-070.xsl	Wed Jul 23 17:02:10 2014 +0200
@@ -23,13 +23,13 @@
   </xsl:template>
   
   <xsl:template match="/">
-      <xsl:apply-templates select=".//book">
+      <xsl:apply-templates select="outermost(.//book)">
         <xsl:with-param name="q" select="23" tunnel="yes"/> 
       </xsl:apply-templates>
   </xsl:template>
   
   <xsl:template match="bookcoll | tstmt | book">
-    <xsl:apply-templates select=".//bktshort"/>
+    <xsl:apply-templates select="outermost(.//bktshort)"/>
   </xsl:template>
   
   <xsl:template match="bktshort">
--- a/tests/strm/sx-PathExpr/sx-path-001.xsl	Wed Jul 23 16:35:29 2014 +0200
+++ b/tests/strm/sx-PathExpr/sx-path-001.xsl	Wed Jul 23 17:02:10 2014 +0200
@@ -1,40 +1,206 @@
-<xsl:stylesheet version="3.0" 
-    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+<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">
-    
+    xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="map xs">
+
     <!-- Test of xsl:stream with several root path expressions -->
+
+    <xsl:param name="test-root1" select="false()" static="yes" as="xs:boolean"/>
+    <xsl:param name="test-root2" select="false()" static="yes" as="xs:boolean"/>
+    <xsl:param name="test-root-pred1" select="false()" static="yes" as="xs:boolean"/>
+    <xsl:param name="test-root-pred2" select="false()" static="yes" as="xs:boolean"/>
+    <xsl:param name="test-root-numpred" select="false()" static="yes" as="xs:boolean"/>
     
-    <xsl:template name="xsl:initial-template">
-      <xsl:variable name="doc" select="doc('../docs/books.xml')" />
-      <xsl:variable name="root1">
-        <xsl:stream href="../docs/books.xml">
-          <xsl:copy-of select="/"/>
-        </xsl:stream>
-      </xsl:variable>
-      <xsl:variable name="root2">
-        <xsl:stream href="../docs/books.xml">
-          <xsl:copy-of select="/BOOKLIST"/>
-        </xsl:stream>
-      </xsl:variable>
-      <xsl:variable name="root3">
-        <xsl:stream href="../docs/books.xml">
-          <xsl:copy-of select="*"/>
-        </xsl:stream>
-      </xsl:variable>
-      <xsl:variable name="root4">
-        <xsl:stream href="../docs/books.xml">
-          <xsl:copy-of select="/*/self::node()[1]"/>
-        </xsl:stream>
-      </xsl:variable>
-      <out>
-        <xsl:value-of select="
-          deep-equal($doc, $root1) and 
-          deep-equal($doc, $root2) and
-          deep-equal($doc, $root3) and 
-          deep-equal($doc, $root4)" />
-      </out>
-    </xsl:template>   
+    <xsl:param name="test-rootelem" select="true()" static="yes" as="xs:boolean"/>
+    <xsl:param name="test-rootelem-self" select="false()" static="yes" as="xs:boolean"/>
+    <xsl:param name="test-rootelem-self-numpred" select="false()" static="yes" as="xs:boolean"/>
+    <xsl:param name="test-doc-nodetest" select="false()" static="yes" as="xs:boolean"/>
+
+    <xsl:variable name="docurl" select="'../docs/books.xml'"/>
+   
+    <xsl:variable name="doc" select="doc($docurl)"/>
+
+    <!-- root expression "/" when context node is statically a root node -->
     
-</xsl:stylesheet>
\ No newline at end of file
+    <xsl:template name="xsl:initial-template" use-when="$test-root1">
+        <xsl:variable name="root">
+            <xsl:stream href="{$docurl}">
+                <xsl:copy-of select="/"/>
+            </xsl:stream>
+        </xsl:variable>
+        <out>
+            <xsl:value-of select="deep-equal($doc, $root)"/>
+        </out>
+    </xsl:template>
+    
+    <!-- root expression "root()" when context node is statically a root node -->
+
+    <xsl:template name="xsl:initial-template" use-when="$test-root2">
+        <xsl:variable name="root">
+            <xsl:stream href="{$docurl}">
+                <xsl:copy-of select="root()"/>
+            </xsl:stream>
+        </xsl:variable>
+        <out>
+            <xsl:value-of select="deep-equal($doc, $root)"/>
+        </out>
+    </xsl:template>
+    
+    <!-- root expression with motionless predicate -->
+    
+    <xsl:template name="xsl:initial-template" use-when="$test-root-pred1">
+        <xsl:variable name="root">
+            <xsl:stream href="{$docurl}">
+                <xsl:copy-of select="(/)[self::node()]"/>
+            </xsl:stream>
+        </xsl:variable>
+        <out>
+            <xsl:value-of select="deep-equal($doc, $root)"/>
+        </out>
+    </xsl:template>
+    
+    <!-- root expression with motionless predicate -->
+    
+    <xsl:template name="xsl:initial-template" use-when="$test-root-pred2">
+        <xsl:variable name="root">
+            <xsl:stream href="{$docurl}">
+                <xsl:copy-of select="(/)[self::node() instance of document-node()]"/>
+            </xsl:stream>
+        </xsl:variable>
+        <out>
+            <xsl:value-of select="deep-equal($doc, $root)"/>
+        </out>
+    </xsl:template>
+    
+    <!-- root expression with numeric predicate -->
+    
+    <xsl:template name="xsl:initial-template" use-when="$test-root-numpred">
+        <xsl:variable name="root">
+            <xsl:stream href="{$docurl}">
+                <xsl:copy-of select="(/)[1]"/>
+            </xsl:stream>
+        </xsl:variable>
+        <out>
+            <xsl:value-of select="deep-equal($doc, $root)"/>
+        </out>
+    </xsl:template>
+    
+    <!-- five variants of root expression with child-select, section 19.8.7.6 and 19.8.8.15 -->
+    
+    <xsl:template name="xsl:initial-template" use-when="$test-rootelem">
+        <xsl:variable name="root1">
+            <xsl:stream href="{$docurl}">
+                <xsl:copy-of select="/BOOKLIST"/>
+            </xsl:stream>
+        </xsl:variable>
+        <xsl:variable name="root2">
+            <xsl:stream href="{$docurl}">
+                <xsl:copy-of select="/*"/>
+            </xsl:stream>
+        </xsl:variable>
+        <xsl:variable name="root3">
+            <xsl:stream href="{$docurl}">
+                <xsl:copy-of select="/element()"/>
+            </xsl:stream>
+        </xsl:variable>
+        <xsl:variable name="root4">
+            <xsl:stream href="{$docurl}">
+                <xsl:copy-of select="root(.)/*"/>
+            </xsl:stream>
+        </xsl:variable>
+        <xsl:variable name="root5">
+            <xsl:stream href="{$docurl}">
+                <xsl:copy-of select="(root(self::node()) treat as document-node())/*"/>
+            </xsl:stream>
+        </xsl:variable>
+        <xsl:variable name="root6">
+            <xsl:stream href="{$docurl}">
+                <!-- see 19.8.7.8 item (1) and bug#xxx -->
+                <xsl:copy-of select="(//*)[1]"/>
+            </xsl:stream>
+        </xsl:variable>
+        <out>
+            <xsl:value-of
+                select="
+                deep-equal($doc, $root1) and
+                deep-equal($doc, $root2) and
+                deep-equal($doc, $root3) and 
+                deep-equal($doc, $root4) and
+                deep-equal($doc, $root5) and
+                deep-equal($doc, $root6)"/>
+        </out>
+    </xsl:template>
+    
+    <!-- five variants of root expression with child-select and motionless predicate, 
+        section 19.8.7.6, 19.8.8.15 and 19.8.7.8 -->
+    
+    <xsl:template name="xsl:initial-template" use-when="$test-rootelem-self">
+        <xsl:variable name="root1">
+            <xsl:stream href="{$docurl}">
+                <xsl:copy-of select="/BOOKLIST"/>
+            </xsl:stream>
+        </xsl:variable>
+        <xsl:variable name="root2">
+            <xsl:stream href="{$docurl}">
+                <xsl:copy-of select="/*"/>
+            </xsl:stream>
+        </xsl:variable>
+        <xsl:variable name="root3">
+            <xsl:stream href="{$docurl}">
+                <xsl:copy-of select="/element()"/>
+            </xsl:stream>
+        </xsl:variable>
+        <xsl:variable name="root4">
+            <xsl:stream href="{$docurl}">
+                <xsl:copy-of select="root(.)/*"/>
+            </xsl:stream>
+        </xsl:variable>
+        <xsl:variable name="root5">
+            <xsl:stream href="{$docurl}">
+                <xsl:copy-of select="(root(self::node()) treat as document-node())/*"/>
+            </xsl:stream>
+        </xsl:variable>
+        <out>
+            <xsl:value-of
+                select="
+                deep-equal($doc, $root1) and
+                deep-equal($doc, $root2) and
+                deep-equal($doc, $root3) and 
+                deep-equal($doc, $root4) and
+                deep-equal($doc, $root5)"/>
+        </out>
+    </xsl:template>
+    
+    <xsl:template name="xsl:initial-template" use-when="false()">
+        <xsl:variable name="root2" as="element()">
+            <xsl:stream href="{$docurl}">
+                <xsl:copy-of select="/BOOKLIST"/>
+            </xsl:stream>
+        </xsl:variable>
+        <xsl:variable name="root3" as="element()">
+            <xsl:stream href="{$docurl}">
+                <xsl:copy-of select="*"/>
+            </xsl:stream>
+        </xsl:variable>
+        <xsl:variable name="root4" as="element()">
+            <xsl:stream href="{$docurl}">
+                <xsl:copy-of select="/*/self::node()[1]"/>
+            </xsl:stream>
+        </xsl:variable>
+        <xsl:variable name="root5" as="element()">
+            <xsl:stream href="{$docurl}">
+                <xsl:copy-of select="/*/self::node()[1]"/>
+            </xsl:stream>
+        </xsl:variable>
+        <out>
+            <xsl:value-of
+                select="
+                deep-equal($doc, $root1/*) and 
+                deep-equal($doc, $root2/*) and
+                deep-equal($doc, $root3/*) and 
+                deep-equal($doc, $root4/*) and
+                deep-equal($doc, $root5/*)"/>
+            <xsl:copy-of select="$root5"/>
+        </out>
+    </xsl:template>
+    
+</xsl:stylesheet>