New tests for composite keys
authorMichael Kay <mike@saxonica.com>
Thu, 17 Aug 2017 10:13:04 +0100
changeset 1744 60ad316ccf04
parent 1743 d4514cf69148
child 1745 575cb2f546a5
child 1746 eceb96fa621d
New tests for composite keys
tests/fn/key/_key-test-set.xml
tests/fn/key/key-094.xsl
tests/fn/key/key-095.xsl
tests/fn/key/key-096.xsl
--- a/tests/fn/key/_key-test-set.xml	Thu Aug 17 10:12:39 2017 +0100
+++ b/tests/fn/key/_key-test-set.xml	Thu Aug 17 10:13:04 2017 +0100
@@ -1750,4 +1750,52 @@
             ></node></root>]]></assert-xml>
       </result>
    </test-case>
+   
+   <test-case name="key-094">
+      <description>Multiple key declarations must have consistent values for @composite</description>
+      <created by="Michael Kay" on="2017-08-16"/>
+      <environment>
+         <source role="." file="key-094.xml"/>
+      </environment>
+      <dependencies>
+         <spec value="XSLT30+"/>
+      </dependencies>
+      <test>
+         <stylesheet file="key-094.xsl"/>
+      </test>
+      <result>
+         <error code="XTSE1222"/>
+      </result>
+   </test-case>
+   
+   <test-case name="key-095">
+      <description>Multiple key declarations must have consistent values for @composite</description>
+      <created by="Michael Kay" on="2017-08-16"/>
+      <environment>
+         <source role="." file="key-094.xml"/>
+      </environment>
+      <dependencies>
+         <spec value="XSLT30+"/>
+      </dependencies>
+      <test>
+         <stylesheet file="key-095.xsl"/>
+      </test>
+      <result>
+         <error code="XTSE1222"/>
+      </result>
+   </test-case>
+   
+   <test-case name="key-096">
+      <description>Composite key with variable number of items</description>
+      <created by="Michael Kay" on="2017-08-16"/>
+      <dependencies>
+         <spec value="XSLT30+"/>
+      </dependencies>
+      <test>
+         <stylesheet file="key-096.xsl"/>
+      </test>
+      <result>
+         <assert>/out = "Hot July brings cooling showers, Apricots and gillyflowers."</assert>
+      </result>
+   </test-case>
 </test-set>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fn/key/key-094.xsl	Thu Aug 17 10:13:04 2017 +0100
@@ -0,0 +1,16 @@
+<?xml version="1.0"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="3.0">
+
+  <!-- Purpose: If there are several xsl:key declarations in the same package with the
+    same key name, then they must all have the same effective value for their composite attribute.. -->
+
+  <xsl:key name="mykey1" match="div" use="title,p[1]" composite="yes"/> 
+  <xsl:key name="mykey1" match="span" use="title,p[1]" composite="no"/> 
+
+  <xsl:template match="doc">
+    <out>
+      <xsl:value-of select="key('mykey1',('Expressions','Exp Section') )/q"/>      
+    </out>
+  </xsl:template>
+
+</xsl:stylesheet>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fn/key/key-095.xsl	Thu Aug 17 10:13:04 2017 +0100
@@ -0,0 +1,16 @@
+<?xml version="1.0"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="3.0">
+
+  <!-- Purpose: If there are several xsl:key declarations in the same package with the
+    same key name, then they must all have the same effective value for their composite attribute.. -->
+
+  <xsl:key name="mykey1" match="div" use="title,p[1]" composite="yes"/> 
+  <xsl:key name="mykey1" match="span" use="title,p[1]"/> 
+
+  <xsl:template match="doc">
+    <out>
+      <xsl:value-of select="key('mykey1',('Expressions','Exp Section') )/q"/>      
+    </out>
+  </xsl:template>
+
+</xsl:stylesheet>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fn/key/key-096.xsl	Thu Aug 17 10:13:04 2017 +0100
@@ -0,0 +1,51 @@
+<?xml version="1.0"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="3.0">
+
+  <!-- Purpose: Composite key with variable number of components -->
+  
+  <xsl:variable name="poem">
+    <verse>January brings the snow,
+    Makes our feet and fingers glow.</verse>
+    
+    <verse>February brings the rain,
+    Thaws the frozen lake again.</verse>
+    
+    <verse>March brings breezes loud and shrill,
+    Stirs the dancing daffodil.</verse>
+    
+    <verse>April brings the primrose sweet,
+    Scatters daises at our feet.</verse>
+    
+    <verse>May brings flocks of pretty lambs,
+    Skipping by their fleecy damns.</verse>
+    
+    <verse>June brings tulips, lilies, roses,
+    Fills the children's hand with posies.</verse>
+    
+    <verse>Hot July brings cooling showers,
+    Apricots and gillyflowers.</verse>
+    
+    <verse>August brings the sheaves of corn,
+    Then the harvest home is borne.</verse>
+    
+    <verse>Warm September brings the fruit,
+    Sportsmen then begin to shoot.</verse>
+    
+    <verse>Fresh October brings the pheasants,
+    Then to gather nuts is pleasant.</verse>
+    
+    <verse>Dull November brings the blast,
+    Then the leaves are whirling fast.</verse>
+    
+    <verse>Chill December brings the sleet,
+    Blazing fire, and Christmas treat. </verse>
+  </xsl:variable>
+  
+  <xsl:key name="k" match="verse" use="substring-before(., ',')!tokenize(.)" composite="1"/> 
+  <xsl:template name="xsl:initial-template">
+    <out>
+      <xsl:value-of select="key('k',tokenize('Hot July brings cooling showers'), $poem) => normalize-space()"/>      
+    </out>
+  </xsl:template>
+
+</xsl:stylesheet>