Skip to content

Commit 1bbcf3e

Browse files
committed
[bugfix] fn:transform stylesheet document crash
The fn:transform code to find the path to the node within the document, for hashing the stylesheet cache, didn’t expect a document. Test for it explicitly, and in the case of a document the URI of the document can serve that purpose.
1 parent dd5eb44 commit 1bbcf3e

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

exist-core/src/main/java/org/exist/xquery/functions/fn/transform/TreeUtils.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import net.sf.saxon.s9api.XdmNode;
2626
import org.exist.xquery.value.NodeValue;
27+
import org.w3c.dom.Document;
2728
import org.w3c.dom.Node;
2829

2930
import java.util.ArrayList;
@@ -36,6 +37,10 @@ private TreeUtils() {
3637
}
3738

3839
static StringBuilder pathTo(final Node node) {
40+
if (node instanceof Document) {
41+
final Document document = (Document) node;
42+
return new StringBuilder().append(document.getDocumentURI());
43+
}
3944
final List<Node> priors = new ArrayList<>();
4045
Node prev = node;
4146
while (prev != null) {
@@ -44,7 +49,7 @@ static StringBuilder pathTo(final Node node) {
4449
}
4550
final Node parent = priors.get(0).getParentNode();
4651
final StringBuilder sb;
47-
if (parent == null) {
52+
if (parent == null || parent instanceof Document) {
4853
sb = new StringBuilder();
4954
} else {
5055
sb = pathTo(parent).append('/');
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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:stylesheet := <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
36+
%test:setUp
37+
function testTransform:setup() {
38+
let $coll := xmldb:create-collection("/db", "regression-test-1")
39+
return (
40+
xmldb:store($coll, "stylesheet.xsl", $testTransform:stylesheet, "application/xslt+xml")
41+
)
42+
};
43+
44+
declare
45+
%test:tearDown
46+
function testTransform:cleanup() {
47+
xmldb:remove("/db/regression-test-1")
48+
};
49+
50+
declare
51+
%test:assertEquals("<v>2</v>")
52+
function testTransform:regression-test-1() {
53+
let $in := parse-xml("<dummy/>")
54+
let $result := ( fn:transform(map{
55+
"source-node":$in,
56+
"stylesheet-node":doc("/db/regression-test-1/stylesheet.xsl"),
57+
"stylesheet-params": map { QName("","v"): "2" } } ) )?output
58+
return $result
59+
};
60+

0 commit comments

Comments
 (0)