Add a test that all element names used in non-error stylesheets satisfy element-available()
authorMichael Kay <mike@saxonica.com>
Tue, 30 Jun 2015 09:21:37 +0100
changeset 994 439f5cc4f449
parent 993 77c252949c59
child 995 cfb78e5d6ca9
Add a test that all element names used in non-error stylesheets satisfy element-available()
tests/misc/catalog/_catalog-test-set.xml
tests/misc/catalog/catalog-006.xsl
--- a/tests/misc/catalog/_catalog-test-set.xml	Tue Jun 30 09:20:40 2015 +0100
+++ b/tests/misc/catalog/_catalog-test-set.xml	Tue Jun 30 09:21:37 2015 +0100
@@ -104,4 +104,21 @@
          <assert>not(/out/invalid)</assert>
       </result>
    </test-case>
+   
+   <test-case name="catalog-006">
+      <description>Test that all XSLT element names in non-error stylesheets satisfy element-available()</description>
+      <keywords>catalog-self-test element-available</keywords>
+      <created by="Michael Kay" on="2015-06-30"/>
+      <environment ref="catalog005"/>
+      <dependencies>
+         <spec value="XSLT30+"/>
+         <feature value="schema_aware"/>
+      </dependencies>
+      <test>
+         <stylesheet file="catalog-006.xsl"/>
+      </test>
+      <result>
+         <assert>not(/out/unavailable)</assert>
+      </result>
+   </test-case>
 </test-set>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/misc/catalog/catalog-006.xsl	Tue Jun 30 09:21:37 2015 +0100
@@ -0,0 +1,28 @@
+<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+  xmlns:cat="http://www.w3.org/2012/10/xslt-test-catalog"
+  xmlns:err="http://www.w3.org/2005/xqt-errors"
+  xmlns:xs="http://www.w3.org/2001/XMLSchema"
+  expand-text="yes"
+  exclude-result-prefixes="xs cat err">
+  
+  <!-- Test that all XSLT element names used in non-error stylesheets satisfy element-available() -->
+  
+  <xsl:param name="DEBUG" static="yes" select="false()"/>
+
+  <xsl:template match="/">
+      <out>
+        <xsl:for-each select="/*/cat:test-set/document(@file)//cat:stylesheet[not(ancestor::cat:test-case//cat:error)]/@file">
+            <xsl:variable name="doc" select="document(.)"/>
+            <xsl:message use-when="$DEBUG">Checking {document-uri($doc)}</xsl:message>
+            <xsl:for-each select="$doc//xsl:*
+                    [not(ancestor-or-self::xsl:*[number(@version) gt 3])]
+                    [not(ancestor-or-self::*[number(@xsl:version) gt 3])]
+                    [not(ancestor-or-self::*/@*:use-when)]
+                    [not(element-available('xsl:'||local-name(.)))]">
+              <unavailable in="{document-uri(/)}">{name()}</unavailable>
+            </xsl:for-each>
+        </xsl:for-each>  
+      </out>
+  </xsl:template>
+
+</xsl:stylesheet>
\ No newline at end of file