Add MusicXML streaming tests from interop workshop
authorMichael Kay <mike@saxonica.com>
Sun, 14 Feb 2016 06:40:48 +0000
changeset 1235 d1fcc93d1fdb
parent 1234 b645114952a6
child 1236 5216a6ccffab
Add MusicXML streaming tests from interop workshop
tests/insn/stream/_stream-test-set.xml
tests/insn/stream/stream-200.xsl
tests/insn/stream/stream-201.xsl
tests/insn/stream/stream-202.xsl
tests/insn/stream/stream-203.xsl
tests/insn/stream/stream-204.xsl
--- a/tests/insn/stream/_stream-test-set.xml	Thu Feb 04 18:58:31 2016 +0000
+++ b/tests/insn/stream/_stream-test-set.xml	Sun Feb 14 06:40:48 2016 +0000
@@ -312,6 +312,76 @@
       </result>
    </test-case>
    
+   <test-case name="stream-200">
+      <description>Extract two parts from a partwise MusicXML score</description>
+      <created by="Michael Kay" on="2016-02-13"/>
+      <test>
+         <stylesheet file="stream-200.xsl"/>
+      </test>
+      <result>
+         <all-of>
+            <assert>exists(//part[@id="P1"])</assert>
+            <assert>exists(//part[@id="P2"])</assert>
+            <assert>empty(//part[@id="P3"])</assert>
+            <assert>empty(//part[@id="P4"])</assert>
+         </all-of>
+      </result>
+   </test-case>
+   
+   <test-case name="stream-201">
+      <description>Extract two parts from a partwise MusicXML score: variant using predicate in pattern</description>
+      <created by="Michael Kay" on="2016-02-13"/>
+      <test>
+         <stylesheet file="stream-201.xsl"/>
+      </test>
+      <result>
+         <all-of>
+            <assert>exists(//part[@id="P1"])</assert>
+            <assert>exists(//part[@id="P2"])</assert>
+            <assert>empty(//part[@id="P3"])</assert>
+            <assert>empty(//part[@id="P4"])</assert>
+         </all-of>
+      </result>
+   </test-case>
+   
+   <test-case name="stream-202">
+      <description>Extract two parts from a partwise MusicXML score: variant using xs:string in map</description>
+      <created by="Michael Kay" on="2016-02-13"/>
+      <test>
+         <stylesheet file="stream-202.xsl"/>
+      </test>
+      <result>
+         <all-of>
+            <assert>exists(//part[@id="P1"])</assert>
+            <assert>exists(//part[@id="P2"])</assert>
+            <assert>empty(//part[@id="P3"])</assert>
+            <assert>empty(//part[@id="P4"])</assert>
+         </all-of>
+      </result>
+   </test-case>
+   
+   <test-case name="stream-203">
+      <description>Extract two parts from a partwise MusicXML score: cannot put xs:untypedAtomic in map that expects xs:string</description>
+      <created by="Michael Kay" on="2016-02-13"/>
+      <test>
+         <stylesheet file="stream-203.xsl"/>
+      </test>
+      <result>
+         <error code="XPTY0004"/>
+      </result>
+   </test-case>
+   
+   <test-case name="stream-204">
+      <description>Extract two parts from a partwise MusicXML score: variant with non-motionless pattern in accumulator rule</description>
+      <created by="Michael Kay" on="2016-02-13"/>
+      <test>
+         <stylesheet file="stream-204.xsl"/>
+      </test>
+      <result>
+         <error code="XTSE3430"/>
+      </result>
+   </test-case>
+   
    <test-case name="stream-500">
       <description>Test xsl:stream instruction. From a Saxon 9.6 bug report (bug 2389).</description>
       <created by="Michael Kay" on="2015-06-05"/>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/insn/stream/stream-200.xsl	Sun Feb 14 06:40:48 2016 +0000
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+    xmlns:xs="http://www.w3.org/2001/XMLSchema"
+    xmlns:map="http://www.w3.org/2005/xpath-functions/map"
+    exclude-result-prefixes="xs"
+    version="3.0">
+    
+    <!-- stylesheet to extract selected parts from a MusicXML score -->
+    
+    <xsl:param name="in" required="no" select="'Psalm100.xml'"/>  <!-- the input file URI -->
+    <xsl:param name="parts" required="no" select="'Cantus+Altus'"/>     <!-- names of the parts to be selected, separated by "+"-->
+    <xsl:variable name="selected-parts" select="tokenize($parts, '\+')"/>    
+        
+    <xsl:accumulator name="selected-part-ids" as="map(xs:untypedAtomic, xs:boolean)" initial-value="map{}" streamable="yes">
+        <xsl:accumulator-rule match="part-name/text()[$selected-parts = current()]">
+            <xsl:sequence select="map:put($value, ../../@id, true())"/>
+        </xsl:accumulator-rule>
+    </xsl:accumulator> 
+        
+    <xsl:mode name="m" on-no-match="shallow-copy" streamable="yes"/>    
+    
+    <xsl:template name="xsl:initial-template">
+        <xsl:stream href="{$in}" use-accumulators="selected-part-ids">
+            <xsl:apply-templates mode="m"/>
+        </xsl:stream>
+    </xsl:template>
+    
+    <xsl:template match="part" mode="m">
+        <xsl:if test="map:contains(accumulator-before('selected-part-ids'), @id)">
+            <xsl:next-match/>
+        </xsl:if>
+    </xsl:template>
+    
+    <!--
+        MHK Note:
+        Mistakes I made while writing this (excluding silly typos).
+        
+        1. Failed to declare the stylesheet with version="3.0" -> Saxon didn't recognise accumulator-before() function
+        2. Failed to cast ../../@id to xs:string -> Type error, map key is xs:untypedAtomic but required type is xs:string
+        3. Failed to declare the accumulator as streamable
+        4. Tried in the match="part" template to put the accumulator test in a predicate of the the match pattern. Failed saying
+        the pattern wasn't motionless
+    
+    -->
+    
+</xsl:stylesheet>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/insn/stream/stream-201.xsl	Sun Feb 14 06:40:48 2016 +0000
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+    xmlns:xs="http://www.w3.org/2001/XMLSchema"
+    xmlns:map="http://www.w3.org/2005/xpath-functions/map"
+    exclude-result-prefixes="xs"
+    version="3.0">
+    
+    <!-- stylesheet to extract selected parts from a MusicXML score -->
+    
+    <xsl:param name="in" required="no" select="'Psalm100.xml'"/>  <!-- the input file URI -->
+    <xsl:param name="parts" required="no" select="'Cantus+Altus'"/>     <!-- names of the parts to be selected, separated by "+"-->
+    <xsl:variable name="selected-parts" select="tokenize($parts, '\+')"/>    
+        
+    <xsl:accumulator name="selected-part-ids" as="map(xs:untypedAtomic, xs:boolean)" initial-value="map{}" streamable="yes">
+        <xsl:accumulator-rule match="part-name/text()[$selected-parts = current()]">
+            <xsl:sequence select="map:put($value, ../../@id, true())"/>
+        </xsl:accumulator-rule>
+    </xsl:accumulator> 
+        
+    <xsl:mode name="m" on-no-match="shallow-copy" streamable="yes"/>    
+    
+    <xsl:template name="xsl:initial-template">
+        <xsl:stream href="{$in}" use-accumulators="selected-part-ids">
+            <xsl:apply-templates mode="m"/>
+        </xsl:stream>
+    </xsl:template>
+    
+    <xsl:template match="part[not(map:contains(accumulator-before('selected-part-ids'), @id))]" mode="m"/>
+    
+    <!--
+        MHK Note:
+        Mistakes I made while writing this (excluding silly typos).
+        
+        1. Failed to declare the stylesheet with version="3.0" -> Saxon didn't recognise accumulator-before() function
+        2. Failed to cast ../../@id to xs:string -> Type error, map key is xs:untypedAtomic but required type is xs:string
+        3. Failed to declare the accumulator as streamable
+        4. Tried in the match="part" template to put the accumulator test in a predicate of the the match pattern. Failed saying
+        the pattern wasn't motionless
+    
+    -->
+    
+</xsl:stylesheet>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/insn/stream/stream-202.xsl	Sun Feb 14 06:40:48 2016 +0000
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+    xmlns:xs="http://www.w3.org/2001/XMLSchema"
+    xmlns:map="http://www.w3.org/2005/xpath-functions/map"
+    exclude-result-prefixes="xs"
+    version="3.0">
+    
+    <!-- stylesheet to extract selected parts from a MusicXML score -->
+    
+    <xsl:param name="in" required="no" select="'Psalm100.xml'"/>  <!-- the input file URI -->
+    <xsl:param name="parts" required="no" select="'Cantus+Altus'"/>     <!-- names of the parts to be selected, separated by "+"-->
+    <xsl:variable name="selected-parts" select="tokenize($parts, '\+')"/>    
+        
+    <xsl:accumulator name="selected-part-ids" as="map(xs:string, xs:boolean)" initial-value="map{}" streamable="yes">
+        <xsl:accumulator-rule match="part-name/text()[$selected-parts = current()]">
+            <xsl:sequence select="map:put($value, xs:string(../../@id), true())"/>
+        </xsl:accumulator-rule>
+    </xsl:accumulator> 
+        
+    <xsl:mode name="m" on-no-match="shallow-copy" streamable="yes"/>    
+    
+    <xsl:template name="xsl:initial-template">
+        <xsl:stream href="{$in}" use-accumulators="selected-part-ids">
+            <xsl:apply-templates mode="m"/>
+        </xsl:stream>
+    </xsl:template>
+    
+    <xsl:template match="part[not(map:contains(accumulator-before('selected-part-ids'), @id))]" mode="m"/>
+    
+    <!--
+        MHK Note:
+        Mistakes I made while writing this (excluding silly typos).
+        
+        1. Failed to declare the stylesheet with version="3.0" -> Saxon didn't recognise accumulator-before() function
+        2. Failed to cast ../../@id to xs:string -> Type error, map key is xs:untypedAtomic but required type is xs:string
+        3. Failed to declare the accumulator as streamable
+        4. Tried in the match="part" template to put the accumulator test in a predicate of the the match pattern. Failed saying
+        the pattern wasn't motionless
+    
+    -->
+    
+</xsl:stylesheet>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/insn/stream/stream-203.xsl	Sun Feb 14 06:40:48 2016 +0000
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+    xmlns:xs="http://www.w3.org/2001/XMLSchema"
+    xmlns:map="http://www.w3.org/2005/xpath-functions/map"
+    exclude-result-prefixes="xs"
+    version="3.0">
+    
+    <!-- stylesheet to extract selected parts from a MusicXML score -->
+    
+    <xsl:param name="in" required="no" select="'Psalm100.xml'"/>  <!-- the input file URI -->
+    <xsl:param name="parts" required="no" select="'Cantus+Altus'"/>     <!-- names of the parts to be selected, separated by "+"-->
+    <xsl:variable name="selected-parts" select="tokenize($parts, '\+')"/>    
+        
+    <xsl:accumulator name="selected-part-ids" as="map(xs:string, xs:boolean)" initial-value="map{}" streamable="yes">
+        <xsl:accumulator-rule match="part-name/text()[$selected-parts = current()]">
+            <xsl:sequence select="map:put($value, ../../@id, true())"/>
+        </xsl:accumulator-rule>
+    </xsl:accumulator> 
+        
+    <xsl:mode name="m" on-no-match="shallow-copy" streamable="yes"/>    
+    
+    <xsl:template name="xsl:initial-template">
+        <xsl:stream href="{$in}" use-accumulators="selected-part-ids">
+            <xsl:apply-templates mode="m"/>
+        </xsl:stream>
+    </xsl:template>
+    
+    <xsl:template match="part[not(map:contains(accumulator-before('selected-part-ids'), @id))]" mode="m"/>
+    
+    <!--
+        MHK Note:
+        Mistakes I made while writing this (excluding silly typos).
+        
+        1. Failed to declare the stylesheet with version="3.0" -> Saxon didn't recognise accumulator-before() function
+        2. Failed to cast ../../@id to xs:string -> Type error, map key is xs:untypedAtomic but required type is xs:string
+        3. Failed to declare the accumulator as streamable
+        4. Tried in the match="part" template to put the accumulator test in a predicate of the the match pattern. Failed saying
+        the pattern wasn't motionless
+    
+    -->
+    
+</xsl:stylesheet>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/insn/stream/stream-204.xsl	Sun Feb 14 06:40:48 2016 +0000
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+    xmlns:xs="http://www.w3.org/2001/XMLSchema"
+    xmlns:map="http://www.w3.org/2005/xpath-functions/map"
+    exclude-result-prefixes="xs"
+    version="3.0">
+    
+    <!-- stylesheet to extract selected parts from a MusicXML score -->
+    
+    <xsl:param name="in" required="no" select="'Psalm100.xml'"/>  <!-- the input file URI -->
+    <xsl:param name="parts" required="no" select="'Cantus+Altus'"/>     <!-- names of the parts to be selected, separated by "+"-->
+    <xsl:variable name="selected-parts" select="tokenize($parts, '\+')"/>    
+        
+    <xsl:accumulator name="selected-part-ids" as="map(xs:string, xs:boolean)" initial-value="map{}" streamable="yes">
+        <xsl:accumulator-rule match="part-name[$selected-parts = current()]">
+            <xsl:sequence select="map:put($value, xs:string(../@id), true())"/>
+        </xsl:accumulator-rule>
+    </xsl:accumulator> 
+        
+    <xsl:mode name="m" on-no-match="shallow-copy" streamable="yes"/>    
+    
+    <xsl:template name="xsl:initial-template">
+        <xsl:stream href="{$in}" use-accumulators="selected-part-ids">
+            <xsl:apply-templates mode="m"/>
+        </xsl:stream>
+    </xsl:template>
+    
+    <xsl:template match="part[not(map:contains(accumulator-before('selected-part-ids'), @id))]" mode="m"/>
+    
+    <!--
+        MHK Note:
+        Mistakes I made while writing this (excluding silly typos).
+        
+        1. Failed to declare the stylesheet with version="3.0" -> Saxon didn't recognise accumulator-before() function
+        2. Failed to cast ../../@id to xs:string -> Type error, map key is xs:untypedAtomic but required type is xs:string
+        3. Failed to declare the accumulator as streamable
+        4. Tried in the match="part" template to put the accumulator test in a predicate of the the match pattern. Failed saying
+        the pattern wasn't motionless
+    
+    -->
+    
+</xsl:stylesheet>
\ No newline at end of file