diff --git a/exist-core/src/main/java/org/exist/xquery/functions/fn/transform/Options.java b/exist-core/src/main/java/org/exist/xquery/functions/fn/transform/Options.java
index e4086fdfc96..ddb59b654d9 100644
--- a/exist-core/src/main/java/org/exist/xquery/functions/fn/transform/Options.java
+++ b/exist-core/src/main/java/org/exist/xquery/functions/fn/transform/Options.java
@@ -32,6 +32,7 @@
import net.sf.saxon.s9api.XdmValue;
import org.apache.commons.lang3.StringUtils;
import org.exist.dom.memtree.NamespaceNode;
+import org.exist.dom.persistent.NodeProxy;
import org.exist.security.PermissionDeniedException;
import org.exist.xquery.ErrorCodes;
import org.exist.xquery.XPathException;
@@ -530,7 +531,12 @@ private Source resolvePossibleStylesheetLocation(final String location) throws X
"Can not access '" + location + "'" + e.getMessage());
}
if (document != null && document.hasOne() && Type.subTypeOf(document.getItemType(), Type.NODE)) {
- return new DOMSource((Node) document.itemAt(0));
+ if (document instanceof NodeProxy proxy) {
+ return new DOMSource(proxy.getNode());
+ }
+ else if (document.itemAt(0) instanceof Node node) {
+ return new DOMSource(node);
+ }
}
throw new XPathException(fnTransform, ErrorCodes.FODC0002,
"Location '"+ location + "' returns an item which is not a document node");
diff --git a/exist-core/src/main/java/org/exist/xquery/functions/fn/transform/Transform.java b/exist-core/src/main/java/org/exist/xquery/functions/fn/transform/Transform.java
index 8689b392d3c..c1c36459de4 100644
--- a/exist-core/src/main/java/org/exist/xquery/functions/fn/transform/Transform.java
+++ b/exist-core/src/main/java/org/exist/xquery/functions/fn/transform/Transform.java
@@ -33,7 +33,6 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.exist.dom.QName;
-import org.exist.dom.memtree.DocumentImpl;
import org.exist.util.Holder;
import org.exist.xquery.ErrorCodes;
import org.exist.xquery.XPathException;
@@ -173,7 +172,7 @@ public Sequence eval(final Sequence[] args, final Sequence contextSequence) thro
final Document document;
Source source = sourceNode.get();
final Node node = ((DOMSource)sourceNode.get()).getNode();
- if (!(node instanceof DocumentImpl)) {
+ if (!(node instanceof org.exist.dom.memtree.DocumentImpl) && !(node instanceof org.exist.dom.persistent.DocumentImpl)) {
//The source may not be a document
//If it isn't, it should be part of a document, so we build a DOMSource to use
document = node.getOwnerDocument();
@@ -190,7 +189,6 @@ public Sequence eval(final Sequence[] args, final Sequence contextSequence) thro
final Transform.TemplateInvocation invocation = new Transform.TemplateInvocation(
options, sourceNode, delivery, xslt30Transformer, resultDocuments);
return invocation.invoke();
-
} catch (final SaxonApiException | UncheckedXPathException e) {
throw originalXPathException("Could not transform input: ", e, ErrorCodes.FOXT0003);
}
@@ -220,7 +218,7 @@ private XsltExecutable compileExecutable(final Options options) throws XPathExce
xsltCompiler.setURIResolver((href, base) -> {
try {
final URI hrefURI = URI.create(href);
- if (!options.resolvedStylesheetBaseURI.isPresent() && !hrefURI.isAbsolute() && StringUtils.isEmpty(base)) {
+ if (options.resolvedStylesheetBaseURI.isEmpty() && !hrefURI.isAbsolute() && StringUtils.isEmpty(base)) {
final XPathException resolutionException = new XPathException(fnTransform,
ErrorCodes.XTSE0165,
"transform using a relative href, \n" +
@@ -263,8 +261,7 @@ private XPathException originalXPathException(final String prefix, @Nonnull fina
cause = e;
while (cause != null) {
- if (cause instanceof net.sf.saxon.trans.XPathException) {
- final net.sf.saxon.trans.XPathException xPathException = (net.sf.saxon.trans.XPathException)cause;
+ if (cause instanceof final net.sf.saxon.trans.XPathException xPathException) {
final StructuredQName from = xPathException.getErrorCodeQName();
if (from != null) {
final QName errorCodeQName = new QName(from.getLocalPart(), from.getURI(), from.getPrefix());
diff --git a/exist-core/src/test/resources/org/exist/xquery/tei-toc.xsl b/exist-core/src/test/resources/org/exist/xquery/tei-toc.xsl
new file mode 100644
index 00000000000..ad2b95eab84
--- /dev/null
+++ b/exist-core/src/test/resources/org/exist/xquery/tei-toc.xsl
@@ -0,0 +1,89 @@
+
+
+ Test document born digitalContents
+
+
+
+