[bugfix] Forward port PR #6544: fix XSLT imports and document builder isolation - #6546
Merged
Conversation
line-o
marked this pull request as draft
July 5, 2026 13:31
Member
Author
|
I propose to squash all four commits |
line-o
marked this pull request as ready for review
July 5, 2026 18:39
… builder isolation Fixes eXist-db#5052 and eXist-db#6065 by porting key changes from develop-6.x.x: 1. Document builder isolation (Delivery.java): - Always use fresh MemTreeBuilder for transform results - Prevents corruption when multiple fn:transform calls occur in same context - Fixes issue eXist-db#6065 where concurrent transforms corrupted each other's output 2. Persistent node handling (Convert.java): - Handle persistent NodeProxy nodes by dereferencing to underlying DOM - Enables passing database-stored nodes as stylesheet parameters - Checks Document interface instead of specific implementation 3. Enhanced stylesheet location resolution (Options.java): - Return Tuple2<String, Source> to track actual resolved location - Sets SystemId on DOMSource for proper relative URI resolution - Fallback resolution for relative URIs using RFC 3986 + database resolution 4. Runtime URI resolution (Transform.java): - Install runtime URI resolver on XSLT controller - Enables fn:document() calls within stylesheets to resolve against database - Integrates with existing URIResolution.CompileTimeURIResolver - Adds helper methods: newFnTransformURIResolver(), databaseBaseURI(), isDatabaseURI() - Supports xsl:include/xsl:import resolution for stylesheets stored in database 5. Build configuration: - Downgrade IzPack to 5.2.3 (5.2.4+ requires Java 9+) Test coverage: - fnTransform5052.xqm: Tests relative xsl:include/import and stylesheet-location resolution - fnTransform6065.xqm: Tests persistent nodes as stylesheet parameters Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Database URIs (paths starting with /, xmldb:, or exist://) should not be resolved against the query context base URI, as they are already absolute database paths. This was preventing the compile-time resolver from correctly using the base URI to resolve relative xsl:include/xsl:import hrefs in stylesheets stored in the database. Fixes test failures in fnTransform5052.xqm where relative stylesheet locations were not being resolved correctly. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
When the owner document's URI is null, use the location parameter as the fallback for the actual location. This ensures the SystemId is always set correctly for the compile-time resolver to use when resolving relative xsl:include/xsl:import hrefs. Fixes remaining test failures where relative stylesheet paths were not being resolved. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
…import paths Fixes issues eXist-db#5052 and eXist-db#6065 by ensuring correct base URI handling for stylesheet resolution: 1. URIResolution.resolveURI: Treat database paths (starting with "/" or "xmldb:") as absolute URIs for relative URI resolution. Previously, paths without a scheme were incorrectly treated as relative, preventing proper resolution of xsl:include/xsl:import hrefs. 2. URIResolution.resolveDocument: Set SystemId on all returned DOMSource objects so that nested includes/imports are resolved with the correct base URI. This ensures xsl:include statements in included stylesheets can correctly resolve their own relative paths. 3. Options.resolvePossibleStylesheetLocation: Simplified to use the resolved location parameter directly as the SystemId, ensuring consistent base URI setup for Saxon's compile-time URI resolver. All fnTransform5052 and fnTransform6065 tests now pass. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Member
Author
dizzzz
reviewed
Jul 6, 2026
dizzzz
approved these changes
Jul 6, 2026
reinhapa
requested changes
Jul 7, 2026
Member
Author
|
Good catches will change code - wonder if this is covered by a codacy rule |
…olution Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ldb: base XmldbURI#getURI strips the xmldb: prefix for xmldb:exist:// URIs but keeps it for the short xmldb:/db/... form, so unconditionally prepending it yielded xmldb:xmldb:/db/... A resolved stylesheet is now its own system id, so this was reached by any relative xsl:import within an imported stylesheet. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
… stylesheet RFC 3986 discards the last segment of the base, which is correct for a document but not for a collection: resolving style.xsl against the collection /db/apps/app yielded /db/apps/style.xsl. A collection and a document are not distinguishable by path alone, so the absence of an extension in the last segment is taken to mean a collection. Outside the database RFC 3986 still applies unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
reinhapa
approved these changes
Jul 12, 2026
dizzzz
approved these changes
Jul 12, 2026
Member
Author
|
What about it? It's mentioned in description. |
Member
Author
|
Is there something that blocks this PR I am not aware of? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Forward port of PR #6544 from develop-6.x.x to develop, fixing critical issues with XSLT stylesheet resolution and document builder isolation in fn:transform. Adapted for Saxon 12.5 compatibility.
Fixes:
What Changed
1. Document Builder Isolation (Delivery.java)
Problem: When multiple fn:transform calls execute in the same XQuery context, they share the same MemTreeBuilder. This causes output corruption when transforms execute concurrently.
Solution: Always use a fresh MemTreeBuilder for each transform result instead of reusing the context's builder.
2. Persistent Node Handling (Convert.java)
Problem: Persistent nodes stored in the database (NodeProxy instances) weren't properly dereferenced when passed as stylesheet parameters.
Solution:
3. XSLT Stylesheet Resolution for Relative URIs (Issue #5052 - Root Cause Fix)
Root Causes (discovered during porting):
URIResolution.resolveURI(): Database paths like "/db/collection/stylesheet.xsl" were incorrectly treated as relative URIs because
URI.isAbsolute()returns false (they lack a scheme component).URIResolution.resolveDocument(): Did not set SystemId on returned DOMSource objects. When Saxon resolved and loaded included stylesheets, it had no base URI for resolving further nested includes.
Options.resolvePossibleStylesheetLocation(): Simplified to use the resolved location directly as SystemId, ensuring consistent base URI setup for Saxon's compile-time resolver.
4. Other Changes
Transform.java: Updated createDestination() call sites to match new Delivery.java signature
Test Coverage
Two comprehensive XQSuite test modules verify all fixes:
Result: All 7110 tests pass with zero failures and zero errors.