Add new test cases for validating elements with an xsi:type attribute
authorMichael Kay <mike@saxonica.com>
Thu, 21 Dec 2017 12:55:11 +0000
changeset 1797 1671206bfbe0
parent 1796 1dc10e8e46f5
child 1798 e67fea782eca
Add new test cases for validating elements with an xsi:type attribute
tests/attr/validation/_validation-test-set.xml
tests/attr/validation/validation-16.xsd
tests/attr/validation/validation-1701.xsl
tests/attr/validation/validation-1705.xsl
--- a/tests/attr/validation/_validation-test-set.xml	Thu Dec 21 11:31:07 2017 +0000
+++ b/tests/attr/validation/_validation-test-set.xml	Thu Dec 21 12:55:11 2017 +0000
@@ -1212,6 +1212,158 @@
       </result>
    </test-case>
    
+   <test-case name="validation-1701">
+      <description>
+         Invalid xsi:type attribute - strict validation
+      </description>
+      <created by="Michael Kay" on="2017-12-21"/>
+      <environment ref="validation-16"/>
+      <dependencies>
+         <spec value="XSLT30+"/>
+         <feature value="schema_aware"/>
+      </dependencies>
+      <test>
+         <stylesheet file="validation-1701.xsl"/>
+         <param name="VALIDATION" static="true" select="'strict'"/>
+      </test>
+      <result>
+         <error code="XTTE1510"/> 
+      </result>
+   </test-case>
+   
+   <test-case name="validation-1702">
+      <description>
+         Invalid xsi:type attribute - lax validation
+      </description>
+      <created by="Michael Kay" on="2017-12-21"/>
+      <environment ref="validation-16"/>
+      <dependencies>
+         <spec value="XSLT30+"/>
+         <feature value="schema_aware"/>
+      </dependencies>
+      <test>
+         <stylesheet file="validation-1701.xsl"/>
+         <param name="VALIDATION" static="true" select="'lax'"/>
+      </test>
+      <result>
+         <error code="XTTE1510"/> 
+      </result>
+   </test-case>
+   
+   <test-case name="validation-1703">
+      <description>
+         Invalid xsi:type attribute - preserve validation
+      </description>
+      <created by="Michael Kay" on="2017-12-21"/>
+      <environment ref="validation-16"/>
+      <dependencies>
+         <spec value="XSLT30+"/>
+         <feature value="schema_aware"/>
+      </dependencies>
+      <test>
+         <stylesheet file="validation-1701.xsl"/>
+         <param name="VALIDATION" static="true" select="'preserve'"/>
+      </test>
+      <result>
+         <assert>exists(/*:doc)</assert>
+      </result>
+   </test-case>
+   
+   <test-case name="validation-1704">
+      <description>
+         Invalid xsi:type attribute - strip validation
+      </description>
+      <created by="Michael Kay" on="2017-12-21"/>
+      <environment ref="validation-16"/>
+      <dependencies>
+         <spec value="XSLT30+"/>
+         <feature value="schema_aware"/>
+      </dependencies>
+      <test>
+         <stylesheet file="validation-1701.xsl"/>
+         <param name="VALIDATION" static="true" select="'strip'"/>
+      </test>
+      <result>
+         <assert>exists(/*:doc)</assert>
+      </result>
+   </test-case>
+   
+   <test-case name="validation-1705">
+      <description>
+         Valid xsi:type attribute - strict validation
+      </description>
+      <created by="Michael Kay" on="2017-12-21"/>
+      <environment ref="validation-16"/>
+      <dependencies>
+         <spec value="XSLT30+"/>
+         <feature value="schema_aware"/>
+      </dependencies>
+      <test>
+         <stylesheet file="validation-1705.xsl"/>
+         <param name="VALIDATION" static="true" select="'strict'"/>
+      </test>
+      <result>
+         <assert>/*:doc instance of schema-element(Q{http://ns.example.com/val16/}doc)</assert>
+      </result>
+   </test-case>
+   
+   <test-case name="validation-1706">
+      <description>
+         Valid xsi:type attribute - lax validation
+      </description>
+      <created by="Michael Kay" on="2017-12-21"/>
+      <environment ref="validation-16"/>
+      <dependencies>
+         <spec value="XSLT30+"/>
+         <feature value="schema_aware"/>
+      </dependencies>
+      <test>
+         <stylesheet file="validation-1705.xsl"/>
+         <param name="VALIDATION" static="true" select="'lax'"/>
+      </test>
+      <result>
+         <assert>/*:doc instance of schema-element(Q{http://ns.example.com/val16/}doc)</assert>
+      </result>
+   </test-case>
+   
+   <test-case name="validation-1707">
+      <description>
+         Valid xsi:type attribute - preserve validation
+      </description>
+      <created by="Michael Kay" on="2017-12-21"/>
+      <environment ref="validation-16"/>
+      <dependencies>
+         <spec value="XSLT30+"/>
+         <feature value="schema_aware"/>
+      </dependencies>
+      <test>
+         <stylesheet file="validation-1705.xsl"/>
+         <param name="VALIDATION" static="true" select="'preserve'"/>
+      </test>
+      <result>
+         <assert>exists(/*:doc)</assert>
+      </result>
+   </test-case>
+   
+   <test-case name="validation-1708">
+      <description>
+         Valid xsi:type attribute - strip validation
+      </description>
+      <created by="Michael Kay" on="2017-12-21"/>
+      <environment ref="validation-16"/>
+      <dependencies>
+         <spec value="XSLT30+"/>
+         <feature value="schema_aware"/>
+      </dependencies>
+      <test>
+         <stylesheet file="validation-1705.xsl"/>
+         <param name="VALIDATION" static="true" select="'strip'"/>
+      </test>
+      <result>
+         <assert>exists(/*:doc)</assert>
+      </result>
+   </test-case>
+   
    <test-case name="validation-2001">
       <description>show patterns matching against nilled and unnilled elements in the source</description>
       <created by="Michael Kay" on="2012-11-07"/>
--- a/tests/attr/validation/validation-16.xsd	Thu Dec 21 11:31:07 2017 +0000
+++ b/tests/attr/validation/validation-16.xsd	Thu Dec 21 12:55:11 2017 +0000
@@ -4,13 +4,13 @@
   xmlns:v16="http://ns.example.com/val16/"
   elementFormDefault="qualified">
   
-  <xs:element name="doc">
-    <xs:complexType>
-      <xs:sequence>
-        <xs:element ref="v16:test" minOccurs="0" maxOccurs="unbounded"/>
-      </xs:sequence>
-    </xs:complexType>
-  </xs:element>
+  <xs:element name="doc" type="v16:docType"/>
+
+  <xs:complexType name="docType">
+    <xs:sequence>
+      <xs:element ref="v16:test" minOccurs="0" maxOccurs="unbounded"/>
+    </xs:sequence>
+  </xs:complexType>
 
 <xs:element name="test">
   <xs:complexType>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/attr/validation/validation-1701.xsl	Thu Dec 21 12:55:11 2017 +0000
@@ -0,0 +1,23 @@
+<?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:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xmlns:v16="http://ns.example.com/val16/"
+  version="3.0" 
+  exclude-result-prefixes="#all">
+  
+  <xsl:param static="yes" name="VALIDATION" as="xs:string" required="yes"/>
+  
+  <xsl:import-schema schema-location="validation-16.xsd" namespace="http://ns.example.com/val16/"/>
+  
+  <!-- Unknown xsi:type is an error for validation=strict/lax, but not for validation=strip/preserve -->
+  
+  <xsl:variable name="var" as="element()">
+    <v16:doc xsi:type="xs:elastic"><v16:test id="ABC"/></v16:doc>
+  </xsl:variable>
+
+  <xsl:template match="/">
+    <xsl:copy-of select="$var" _validation="{$VALIDATION}"/>
+  </xsl:template>
+
+</xsl:stylesheet>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/attr/validation/validation-1705.xsl	Thu Dec 21 12:55:11 2017 +0000
@@ -0,0 +1,23 @@
+<?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:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xmlns:v16="http://ns.example.com/val16/"
+  version="3.0" 
+  exclude-result-prefixes="#all">
+  
+  <xsl:param static="yes" name="VALIDATION" as="xs:string" required="yes"/>
+  
+  <xsl:import-schema schema-location="validation-16.xsd" namespace="http://ns.example.com/val16/"/>
+  
+  <!-- Unknown xsi:type is an error for validation=strict/lax, but not for validation=strip/preserve -->
+  
+  <xsl:variable name="var" as="element()">
+    <v16:doc xsi:type="v16:docType"><v16:test id="ABC"/></v16:doc>
+  </xsl:variable>
+
+  <xsl:template match="/">
+    <xsl:copy-of select="$var" _validation="{$VALIDATION}"/>
+  </xsl:template>
+
+</xsl:stylesheet>