|
| 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 | +import module namespace xmldb="http://exist-db.org/xquery/xmldb"; |
| 26 | +declare namespace test="http://exist-db.org/xquery/xqsuite"; |
| 27 | + |
| 28 | +declare variable $testTransform:stylesheet1 := <xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'> |
| 29 | + <xsl:param name='v'/> |
| 30 | + <xsl:template match='/'> |
| 31 | + <v><xsl:value-of select='$v'/></v> |
| 32 | + </xsl:template> |
| 33 | +</xsl:stylesheet>; |
| 34 | + |
| 35 | +declare variable $testTransform:stylesheet2 := <xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'> |
| 36 | + <xsl:param name='v'/> |
| 37 | + <xsl:template name='named-template' match='/'> |
| 38 | + <v><xsl:value-of select='$v'/></v> |
| 39 | + </xsl:template> |
| 40 | +</xsl:stylesheet>; |
| 41 | + |
| 42 | +declare variable $testTransform:document := <document> |
| 43 | + <catalog> |
| 44 | + <book id="bk101"> |
| 45 | + <author>Gambardella, Matthew</author> |
| 46 | + <title>XML Developer's Guide</title> |
| 47 | + <genre>Computer</genre> |
| 48 | + <price>44.95</price> |
| 49 | + <publish_date>2000-10-01</publish_date> |
| 50 | + <description>An in-depth look at creating applications |
| 51 | + with XML.</description> |
| 52 | + </book> |
| 53 | + <book id="bk102"> |
| 54 | + <author>Ralls, Kim</author> |
| 55 | + <title>Midnight Rain</title> |
| 56 | + <genre>Fantasy</genre> |
| 57 | + <price>5.95</price> |
| 58 | + <publish_date>2000-12-16</publish_date> |
| 59 | + <description>A former architect battles corporate zombies, |
| 60 | + an evil sorceress, and her own childhood to become queen |
| 61 | + of the world.</description> |
| 62 | + </book> |
| 63 | + </catalog> |
| 64 | +</document>; |
| 65 | +
|
| 66 | +declare |
| 67 | + %test:setUp |
| 68 | +function testTransform:setup() { |
| 69 | + let $coll := xmldb:create-collection("/db", "regression-test") |
| 70 | + let $storeStylesheet1 := xmldb:store($coll, "stylesheet1.xsl", $testTransform:stylesheet1, "application/xslt+xml") |
| 71 | + let $storeStylesheet2 := xmldb:store($coll, "stylesheet2.xsl", $testTransform:stylesheet2, "application/xslt+xml") |
| 72 | + let $storeDocument := xmldb:store($coll, "document.xml", $testTransform:document, "application/document") |
| 73 | + return () |
| 74 | +}; |
| 75 | +
|
| 76 | +declare |
| 77 | + %test:tearDown |
| 78 | +function testTransform:cleanup() { |
| 79 | + xmldb:remove("/db/regression-test") |
| 80 | +}; |
| 81 | +
|
| 82 | +declare |
| 83 | + %test:assertEquals("<v>Gambardella, MatthewXML Developer's GuideComputer44.952000-10-01An in-depth look at creating applications |
| 84 | + with XML.Ralls, KimMidnight RainFantasy5.952000-12-16A former architect battles corporate zombies, |
| 85 | + an evil sorceress, and her own childhood to become queen |
| 86 | + of the world.</v>") |
| 87 | +function testTransform:regression-test-1() { |
| 88 | + let $in := parse-xml("<dummy/>") |
| 89 | + let $result := ( fn:transform(map{ |
| 90 | + "source-node":$in, |
| 91 | + "stylesheet-node":doc("/db/regression-test/stylesheet1.xsl"), |
| 92 | + "stylesheet-params": map { QName("","v"): doc("/db/regression-test/document.xml") } } ) )?output |
| 93 | + return $result |
| 94 | +}; |
| 95 | +
|
| 96 | +declare |
| 97 | + %test:assertEquals("<v>Gambardella, MatthewXML Developer's GuideComputer44.952000-10-01An in-depth look at creating applications |
| 98 | + with XML.Ralls, KimMidnight RainFantasy5.952000-12-16A former architect battles corporate zombies, |
| 99 | + an evil sorceress, and her own childhood to become queen |
| 100 | + of the world.</v>") |
| 101 | +function testTransform:regression-test-2() { |
| 102 | + let $in := parse-xml("<dummy/>") |
| 103 | + let $result := ( fn:transform(map{ |
| 104 | + "source-node":$in, |
| 105 | + "stylesheet-node":doc("/db/regression-test/stylesheet2.xsl"), |
| 106 | + "initial-template": QName('', 'named-template'), |
| 107 | + "global-context-item" : fn:doc("/db/regression-test/document.xml"), |
| 108 | + "stylesheet-params": map { |
| 109 | + QName('', 'v'): fn:doc("/db/regression-test/document.xml") |
| 110 | + }}))?output |
| 111 | + return $result |
| 112 | +}; |
| 113 | +
|
| 114 | +
|
0 commit comments