|
| 1 | +(: |
| 2 | + : eXist-db Open Source Native XML Database |
| 3 | + : Copyright (C) 2001 The eXist-db Authors |
| 4 | + : |
| 5 | + |
| 6 | + : http://www.exist-db.org |
| 7 | + : |
| 8 | + : This library is free software; you can redistribute it and/or |
| 9 | + : modify it under the terms of the GNU Lesser General Public |
| 10 | + : License as published by the Free Software Foundation; either |
| 11 | + : version 2.1 of the License, or (at your option) any later version. |
| 12 | + : |
| 13 | + : This library is distributed in the hope that it will be useful, |
| 14 | + : but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | + : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | + : Lesser General Public License for more details. |
| 17 | + : |
| 18 | + : You should have received a copy of the GNU Lesser General Public |
| 19 | + : License along with this library; if not, write to the Free Software |
| 20 | + : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 21 | + :) |
| 22 | +xquery version "3.1"; |
| 23 | + |
| 24 | +module namespace testTransform="http://exist-db.org/xquery/test/function_transform"; |
| 25 | + |
| 26 | +declare namespace test="http://exist-db.org/xquery/xqsuite"; |
| 27 | + |
| 28 | +declare variable $testTransform:transform-68-xsl := document { <xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' |
| 29 | + xmlns:xs='http://www.w3.org/2001/XMLSchema' |
| 30 | + xmlns:saxon='http://saxon.sf.net/' |
| 31 | + xmlns:my='http://www.w3.org/fots/fn/transform/myfunctions' version='2.0'> |
| 32 | + <xsl:param name='v'/> |
| 33 | + <xsl:template name='main'> |
| 34 | + <out><xsl:value-of select='$v'/></out> |
| 35 | + </xsl:template> |
| 36 | + </xsl:stylesheet> }; |
| 37 | + |
| 38 | +declare variable $testTransform:transform-68-xsl-text := "<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' |
| 39 | + xmlns:xs='http://www.w3.org/2001/XMLSchema' |
| 40 | + xmlns:saxon='http://saxon.sf.net/' |
| 41 | + xmlns:my='http://www.w3.org/fots/fn/transform/myfunctions' version='2.0'> |
| 42 | + <xsl:param name='v'/> |
| 43 | + <xsl:template name='main'> |
| 44 | + <out><xsl:value-of select='$v'/></out> |
| 45 | + </xsl:template> |
| 46 | + </xsl:stylesheet>"; |
| 47 | + |
| 48 | +declare variable $testTransform:transform-33-xsl := "<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='3.0'> |
| 49 | + <xsl:template match='/'> <xsl:for-each select='//section'> |
| 50 | + <xsl:result-document href='section{position()}.html'> <!-- instructions content here --> |
| 51 | + </xsl:result-document> </xsl:for-each> |
| 52 | + </xsl:template> </xsl:stylesheet>"; |
| 53 | + |
| 54 | +declare variable $testTransform:transform-33-xml := "<doc> |
| 55 | + <section>sect1</section> |
| 56 | + <section>sect2</section> |
| 57 | + <section>sect3</section> |
| 58 | + </doc>"; |
| 59 | +declare |
| 60 | + %test:assertError("err:FODC0002") |
| 61 | +function testTransform:transform-stylesheet-location() { |
| 62 | + let $result := fn:transform(map {"stylesheet-location" : "http://www.w3.org/fots/fn/transform/staticbaseuri.xsl", |
| 63 | + "initial-template" : QName('','main'), |
| 64 | + "stylesheet-base-uri": "http://www.example.com"}) |
| 65 | + return $result?output |
| 66 | +}; |
| 67 | + |
| 68 | +declare |
| 69 | + %test:assertError("err:FODC0002") |
| 70 | +function testTransform:transform-stylesheet-location-relative() { |
| 71 | + let $result := fn:transform(map {"stylesheet-location" : "transform/staticbaseuri.xsl", |
| 72 | + "initial-template" : QName('','main'), |
| 73 | + "stylesheet-base-uri": "http://www.example.com"}) |
| 74 | + return $result?output |
| 75 | +}; |
| 76 | + |
| 77 | +declare |
| 78 | + %test:assertTrue |
| 79 | +function testTransform:transform-stylesheet-ok() { |
| 80 | + let $xsl := $testTransform:transform-33-xsl |
| 81 | + let $xml := $testTransform:transform-33-xml |
| 82 | + let $result := fn:transform(map {"stylesheet-text": $xsl, "source-node": parse-xml($xml), |
| 83 | + "base-output-uri" : resolve-uri("transform/sandbox/fn-transform-33.xml", "http://www.w3.org/fots/fn/transform/staticbaseuri.xsl"), |
| 84 | + "delivery-format":"serialized"}) |
| 85 | + return (contains(string-join(map:keys($result)),"section2")) |
| 86 | +}; |
| 87 | + |
| 88 | +declare |
| 89 | + %test:assertError("err:XPTY0004") |
| 90 | +function testTransform:transform-stylesheet-bad-xslt-version() { |
| 91 | + let $xsl := $testTransform:transform-33-xsl |
| 92 | + let $xml := $testTransform:transform-33-xml |
| 93 | + let $result := fn:transform(map {"stylesheet-text": $xsl, "source-node": parse-xml($xml), |
| 94 | + "xslt-version": "hi", |
| 95 | + "base-output-uri" : resolve-uri("transform/sandbox/fn-transform-33.xml", "http://www.w3.org/fots/fn/transform/staticbaseuri.xsl"), |
| 96 | + "delivery-format":"serialized"}) |
| 97 | + return (contains(string-join(map:keys($result)),"section2")) |
| 98 | +}; |
| 99 | + |
| 100 | +declare |
| 101 | + %test:assertError("err:FOXT0001") |
| 102 | +function testTransform:transform-stylesheet-invalid-xslt-version() { |
| 103 | + let $xsl := $testTransform:transform-33-xsl |
| 104 | + let $xml := $testTransform:transform-33-xml |
| 105 | + let $result := fn:transform(map {"stylesheet-text": $xsl, "source-node": parse-xml($xml), |
| 106 | + "xslt-version": 4.0, |
| 107 | + "base-output-uri" : resolve-uri("transform/sandbox/fn-transform-33.xml", "http://www.w3.org/fots/fn/transform/staticbaseuri.xsl"), |
| 108 | + "delivery-format":"serialized"}) |
| 109 | + return (contains(string-join(map:keys($result)),"section2")) |
| 110 | +}; |
| 111 | + |
| 112 | +(: cannot have stylesheet-node and stylesheet-text :) |
| 113 | +declare |
| 114 | + %test:assertError("err:FOXT0002") |
| 115 | +function testTransform:transform-stylesheet-node-and-text() { |
| 116 | + let $xsl := $testTransform:transform-68-xsl |
| 117 | + let $xsl-text := $testTransform:transform-68-xsl-text |
| 118 | + let $result := fn:transform(map {"stylesheet-node" : $xsl, |
| 119 | + "stylesheet-text" : $xsl-text, |
| 120 | + "initial-template" : QName('','main'), |
| 121 | + "stylesheet-base-uri": "http://www.example.com"}) |
| 122 | + return $result?output |
| 123 | +}; |
| 124 | + |
| 125 | +(: need to supply a stylesheet, error if we don't :) |
| 126 | +declare |
| 127 | + %test:assertError("err:FOXT0002") |
| 128 | +function testTransform:transform-stylesheet-not-provided() { |
| 129 | + let $result := fn:transform(map {"initial-template" : QName('','main'), |
| 130 | + "stylesheet-base-uri": "http://www.example.com"}) |
| 131 | + return $result?output |
| 132 | +}; |
0 commit comments