Add an xsl:merge test using accumulators
authorMichael Kay <mike@saxonica.com>
Wed, 12 Aug 2015 10:49:01 +0100
changeset 1032 c4562c4c8ea0
parent 1031 2ec657f16920
child 1033 82df2f880108
Add an xsl:merge test using accumulators
tests/insn/merge/_merge-test-set.xml
tests/insn/merge/merge-065.xsl
--- a/tests/insn/merge/_merge-test-set.xml	Wed Aug 12 10:18:21 2015 +0100
+++ b/tests/insn/merge/_merge-test-set.xml	Wed Aug 12 10:49:01 2015 +0100
@@ -951,5 +951,23 @@
          <error code="XTSE0020"/>
       </result>
    </test-case>
+   
+   <test-case name="merge-065">
+      <description>xsl:merge test using accumulators.</description>
+      <created by="Michael Kay" on="2015-08-12"/>
+      <environment ref="merge002"/>
+      <test>
+         <stylesheet file="merge-065.xsl"/>
+      </test>
+      <result>
+         <all-of>
+           <assert>/events/group[1]/item[1][ends-with(., 'log-file-1.xml - events')]</assert>
+           <assert>/events/group[1]/item[2][ends-with(., 'log-file-2.xml - log/day')]</assert>
+           <assert>/events/group[1]/event[@timestamp="2009-08-20T12:01:01Z"]</assert>
+           <assert>/events/group[1]/record[message='Temperature 15.4C']/time</assert>
+           <assert>/events/group[5]/item[1][ends-with(., 'log-file-2.xml - log/day')]</assert>
+         </all-of>
+      </result>
+   </test-case>
 
 </test-set>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/insn/merge/merge-065.xsl	Wed Aug 12 10:49:01 2015 +0100
@@ -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"
+    exclude-result-prefixes="xs"
+    version="3.0">
+    <!-- xsl:merge test using accumulators. -->
+    
+    <xsl:output method="xml" indent="no"/>
+    <xsl:strip-space elements="*"/>
+    <xsl:template match="/">
+        
+        <events>
+            <xsl:merge>
+                <xsl:merge-source for-each-stream="'log-file-1.xml'" select="events/event">
+                        <xsl:merge-key select="xs:dateTime(@timestamp)"/>
+                </xsl:merge-source>
+                <xsl:merge-source for-each-stream="'log-file-2.xml'" select="log/day/record">
+                        <xsl:merge-key select="dateTime(../@date, time)"/>
+                </xsl:merge-source>
+                <xsl:merge-action>
+                    <group>
+                        <xsl:for-each select="current-merge-group()">
+                          <item><xsl:value-of select="accumulator-before('path')"/></item>
+                        </xsl:for-each>  
+                        <xsl:copy-of select="current-merge-group()" />
+                    </group>
+                </xsl:merge-action>
+            </xsl:merge>
+        </events>
+        
+    </xsl:template>
+    
+    <xsl:accumulator name="path" initial-value="''">
+      <xsl:accumulator-rule match="*" select="concat(document-uri(/), ' - ', string-join(ancestor::*/name(), '/'))"/>
+    </xsl:accumulator>  
+</xsl:stylesheet>
\ No newline at end of file