New test: type annotation for element with complex type + simple content default tip
authorMichael Kay <mike@saxonica.com>
Thu, 18 Jan 2018 16:06:42 +0000
changeset 1814 2c63493cda70
parent 1813 af284262f61e
New test: type annotation for element with complex type + simple content
tests/attr/as/_as-test-set.xml
tests/attr/as/as-3701.xsl
--- a/tests/attr/as/_as-test-set.xml	Thu Jan 18 16:05:46 2018 +0000
+++ b/tests/attr/as/_as-test-set.xml	Thu Jan 18 16:06:42 2018 +0000
@@ -4001,4 +4001,19 @@
          </all-of>
       </result>
    </test-case>
+   
+   <test-case name="as-3701">
+      <description>Type annotation of complex type with simple content. Saxon bug 3628</description>
+      <created by="Michael Kay" on="2018-01-16"/>
+      <dependencies>
+         <spec value="XSLT30+"/>
+         <feature value="schema_aware"/>
+      </dependencies>
+      <test>
+         <stylesheet file="as-3701.xsl"/>
+      </test>
+      <result>
+         <assert-xml><![CDATA[<tns:r xmlns:tns="http://www.3701.com"><tns:t id="t-1">one</tns:t></tns:r>]]></assert-xml>
+      </result>
+   </test-case>
 </test-set>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/attr/as/as-3701.xsl	Thu Jan 18 16:06:42 2018 +0000
@@ -0,0 +1,49 @@
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+  xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://www.3701.com" version="3.0" exclude-result-prefixes="xs">
+  
+  <xsl:import-schema namespace="http://www.3701.com">
+    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
+      targetNamespace="http://www.3701.com" xmlns:tns="http://www.3701.com">
+      <xs:element name="r">
+        <xs:complexType>
+          <xs:sequence>
+            <xs:element maxOccurs="unbounded" name="t" type="tns:T"/>
+          </xs:sequence>
+        </xs:complexType>
+      </xs:element>
+      <xs:complexType name="T">
+        <xs:simpleContent>
+          <xs:extension base="xs:string">
+            <xs:attribute name="id" type="xs:ID"/>
+          </xs:extension>
+        </xs:simpleContent>
+      </xs:complexType>
+    </xs:schema>
+  </xsl:import-schema>
+  
+  <xsl:template match="input" as="schema-element(tns:r)">
+    <xsl:variable name="tList" as="element(*, tns:T)">
+      <xsl:apply-templates select="*"/>
+    </xsl:variable>
+    <tns:r xsl:validation="strict">
+      <xsl:sequence select="$tList"/>
+    </tns:r>
+  </xsl:template>
+  
+  <xsl:template match="s" as="element(*, tns:T)">
+    <tns:t xsl:type="tns:T">
+      <xsl:attribute name="id" select="concat('t-', count(preceding-sibling::*) + 1)"/>
+      <xsl:value-of select="."/>
+    </tns:t>
+  </xsl:template>
+  
+  <xsl:template name="xsl:initial-template">
+    <xsl:variable name="in">
+      <input>
+        <s>one</s>
+      </input>
+    </xsl:variable>
+    <xsl:apply-templates select="$in"/>
+  </xsl:template>
+  
+</xsl:stylesheet>
\ No newline at end of file