Basic tests that fn:transform works in XSLT
authorMichael Kay <mike@saxonica.com>
Tue, 24 Apr 2018 17:11:08 +0100
changeset 1837 14d1819c8f0f
parent 1836 346f3ba92c11
child 1838 48b480e3c5ca
Basic tests that fn:transform works in XSLT
tests/fn/transform/_transform-test-set.xml
tests/fn/transform/transform-001.xsl
tests/fn/transform/transform-002.xsl
tests/fn/transform/transform-003.xsl
tests/fn/transform/transform-004.xsl
tests/fn/transform/transform-004a.xsl
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fn/transform/_transform-test-set.xml	Tue Apr 24 17:11:08 2018 +0100
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<test-set xmlns="http://www.w3.org/2012/10/xslt-test-catalog" xmlns:xs="http://www.w3.org/2001/XMLSchema" name="transform">
+   <description>Tests transform() function in XSLT 3.0 (requires XPath 3.1)</description>
+   
+   
+   <dependencies>
+      <spec value="XSLT30+"/>
+      <feature value="XPath_3.1"/>
+      <feature value="higher_order_functions"/>
+   </dependencies>
+
+   <test-case name="transform-001">
+      <description>Returns error, module is not available (non-existent file)</description>
+      <created by="Michael Kay" on="2018-04-18"/>           
+      <test>
+         <stylesheet file="transform-001.xsl"/>
+         <initial-template name="main"/>
+      </test>
+      <result>
+         <error code="FOXT0002"/>
+      </result>
+   </test-case>
+   
+   <test-case name="transform-002">
+      <description>Simple successful transformation</description>
+      <created by="Michael Kay" on="2018-04-18"/>           
+      <test>
+         <stylesheet file="transform-002.xsl"/>
+         <initial-template name="main"/>
+      </test>
+      <result>
+         <assert>/out/in = 59</assert>
+      </result>
+   </test-case>
+   
+   <test-case name="transform-003">
+      <description>fn:transform() returns a function which is then called in the calling stylesheet</description>
+      <created by="Michael Kay" on="2018-04-18"/>           
+      <test>
+         <stylesheet file="transform-003.xsl"/>
+         <initial-template name="main"/>
+      </test>
+      <result>
+         <assert>/out = 3.142</assert>
+      </result>
+   </test-case>
+   
+   <test-case name="transform-004">
+      <description>fn:transform() in a static expression returns a function</description>
+      <created by="Michael Kay" on="2018-04-18"/>           
+      <test>
+         <stylesheet file="transform-004.xsl"/>
+         <initial-template name="main"/>
+      </test>
+      <result>
+         <assert>/out = 42</assert>
+      </result>
+   </test-case>
+
+
+</test-set>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fn/transform/transform-001.xsl	Tue Apr 24 17:11:08 2018 +0100
@@ -0,0 +1,14 @@
+<?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"
+    exclude-result-prefixes="xs"
+    version="3.0"
+    expand-text="yes">
+    
+    <xsl:template name="main">
+        <out>
+            <xsl:sequence select="transform( map { 'stylesheet-location': 'non-existent.xsl', 'initial-match-selection' : 42})"/>
+        </out>
+    </xsl:template>
+    
+</xsl:stylesheet>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fn/transform/transform-002.xsl	Tue Apr 24 17:11:08 2018 +0100
@@ -0,0 +1,18 @@
+<?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"
+    exclude-result-prefixes="xs"
+    version="3.0"
+    expand-text="yes">
+    
+    <xsl:template name="main">
+        <out>
+            <xsl:sequence select="transform( map { 'stylesheet-location': 'transform-002.xsl', 'initial-match-selection' : 42})?output"/>
+        </out>
+    </xsl:template>
+    
+    <xsl:template match=".[. instance of xs:integer]">
+        <in>{17 + .}</in>
+    </xsl:template>
+    
+</xsl:stylesheet>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fn/transform/transform-003.xsl	Tue Apr 24 17:11:08 2018 +0100
@@ -0,0 +1,19 @@
+<?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"
+    exclude-result-prefixes="xs"
+    version="3.0"
+    expand-text="yes">
+    
+    <xsl:template name="main">
+        <out>
+            <xsl:sequence select="transform( map { 'stylesheet-location': 'transform-003.xsl', 
+                'initial-match-selection' : 3, 'delivery-format' : 'raw'})?output(3.14159)"/>
+        </out>
+    </xsl:template>
+    
+    <xsl:template match=".[. instance of xs:integer]">
+        <xsl:sequence select="round(?, .)"/>
+    </xsl:template>
+    
+</xsl:stylesheet>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fn/transform/transform-004.xsl	Tue Apr 24 17:11:08 2018 +0100
@@ -0,0 +1,16 @@
+<?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"
+    exclude-result-prefixes="xs"
+    version="3.0"
+    expand-text="yes">
+    
+    <xsl:variable name="decider" static="yes" select="transform( map { 'stylesheet-location': 'transform-004a.xsl', 
+        'initial-template' : QName('', 'get-function'), 'delivery-format' : 'raw'})?output"/>
+    
+    <xsl:template name="main">
+        <out xsl:use-when="$decider(-1)">42</out>
+        <out xsl:use-when="not($decider(-1))">24</out>
+    </xsl:template>
+
+</xsl:stylesheet>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fn/transform/transform-004a.xsl	Tue Apr 24 17:11:08 2018 +0100
@@ -0,0 +1,18 @@
+<?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:f="f"
+    exclude-result-prefixes="xs f"
+    version="3.0"
+    expand-text="yes">
+
+    <xsl:template name="get-function">
+        <xsl:sequence select="f:negative#1"/>
+    </xsl:template>
+    
+    <xsl:function name="f:negative" as="xs:boolean">
+        <xsl:param name="in" as="xs:integer"/>
+        <xsl:sequence select="$in lt 0"/>
+    </xsl:function>
+
+</xsl:stylesheet>
\ No newline at end of file