Skip to content

Commit 07de7d6

Browse files
committed
[bugfix] Make sure that /db URIs are converted to xmldb:exist:///db URIs when setting Base URI for XSLT transformations
1 parent 99ef5fd commit 07de7d6

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import net.sf.saxon.s9api.QName;
5555
import net.sf.saxon.s9api.XdmValue;
5656
import org.exist.dom.memtree.NamespaceNode;
57+
import org.exist.xmldb.XmldbURI;
5758
import org.exist.xquery.ErrorCodes;
5859
import org.exist.xquery.XPathException;
5960
import org.exist.xquery.XQueryContext;
@@ -490,7 +491,13 @@ private Tuple2<String, Source> getStylesheet(final MapType options) throws XPath
490491
final List<Tuple2<String, Source>> results = new ArrayList<>(1);
491492
final Optional<String> stylesheetLocation = Options.STYLESHEET_LOCATION.get(options).map(StringValue::getStringValue);
492493
if (stylesheetLocation.isPresent()) {
493-
results.add(Tuple(stylesheetLocation.get(), resolveStylesheetLocation(stylesheetLocation.get())));
494+
final String strStylesheetLocationUri;
495+
if (stylesheetLocation.get().startsWith("/db/")) {
496+
strStylesheetLocationUri = XmldbURI.EMBEDDED_SERVER_URI_PREFIX + stylesheetLocation.get();
497+
} else {
498+
strStylesheetLocationUri = stylesheetLocation.get();
499+
}
500+
results.add(Tuple(strStylesheetLocationUri, resolveStylesheetLocation(stylesheetLocation.get())));
494501
}
495502

496503
final Optional<Node> stylesheetNode = Options.STYLESHEET_NODE.get(options).map(NodeValue::getNode);

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,11 @@ public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathExce
181181

182182
// Parameter 1 & 2
183183
final Sequence inputNode = args[0];
184-
final Item stylesheetItem = args[1].itemAt(0);
184+
Item stylesheetItem = args[1].itemAt(0);
185+
if (stylesheetItem instanceof StringValue sv && sv.toString().startsWith("/db/")) {
186+
// adjust /db like URI to xmldb:exist:///db/ like URI
187+
stylesheetItem = new StringValue(XmldbURI.EMBEDDED_SERVER_URI_PREFIX + sv.toString().substring(3));
188+
}
185189

186190
// Parse 3rd parameter
187191
final Node options = args[2].isEmpty() ? null : ((NodeValue) args[2].itemAt(0)).getNode();

0 commit comments

Comments
 (0)