Skip to content

[Dev6] fix XSLT imports - #6544

Merged
dizzzz merged 4 commits into
eXist-db:develop-6.x.xfrom
line-o:dev6-fix-xslt-imports
Jul 6, 2026
Merged

[Dev6] fix XSLT imports#6544
dizzzz merged 4 commits into
eXist-db:develop-6.x.xfrom
line-o:dev6-fix-xslt-imports

Conversation

@line-o

@line-o line-o commented Jul 4, 2026

Copy link
Copy Markdown
Member

Description:

Fixes several long-standing issues with imports and URI resolution in fn:transform

Reference:

fixes #5052
refs #6065

Type of tests:

XQSuite tests added

line-o added 4 commits July 4, 2026 09:57
In order to build develop-6.x.x we need to downgrade IzPack to the latest version that does
not have the transitive dependency on org.pushing-pixels:radiance-theming(-extras) v7.5.0
Because that requires Java 9 to compile. This is likely an unintentional change or bug upstream.
Passing persistent nodes from XQuery to fn:transform as parameters works now.
- dereference NodeProxy objects in Convert.of(Sequence)
- match both persistent and in-memory Documents in Convert.ofNode(Node)

Backport of fddbfd3
refs eXist-db#6065

With this PR applied the shared document builder from the parent XqueryContext is never used.
As a result two calls to fn:transform within the same context no longer corrupt each others return values.
The actual root-cause of what is described in the linked gist:
https://gist.github.com/line-o/4731ed367f437be9cd036b152a18d340
fn:transform did not resolve relative URIs against the database:
relative xsl:include/xsl:import hrefs in stored stylesheets, and a
relative stylesheet-location, would not resolve the way fn:doc and
transform:transform already do. In particular a declared base-uri
pointing at a collection without a trailing slash could lose its
last path segment during resolution.

- Add Transform.newFnTransformURIResolver, leveraging the existing
  XsltURIResolverHelper.getXsltURIResolver. It is installed in two
  places: on the XsltCompiler (resolves relative xsl:include/
  xsl:import at compile time) and on the Xslt30Transformer's
  controller (resolves runtime lookups such as fn:doc()/document()
  inside the stylesheet).
- Transform.databaseBaseURI derives the base to resolve against:
  the stylesheet's own resolved base URI if it's a database
  location (isDatabaseURI), otherwise falling back to the querying
  module's location in the database when the stylesheet was built
  in-memory (stylesheet-node/stylesheet-text with no explicit
  stylesheet-base-uri).
- New error path: stylesheet-text with a relative href and no
  stylesheet-base-uri now raises XTSE0165 instead of resolving
  incorrectly.
- Options.resolveStylesheetLocation now encapsulates discerning
  relative/absolute/external stylesheet-location values and returns
  the Tuple directly, rather than that logic living in
  Options.getStylesheet.

XQSuite tests added in fnTransform5052.xqm.

refs eXist-db#5052

NOTE: This fixes the relative imports in XSLT for develop-6; the issue
will be closed once the patch is forward-ported to develop.
@line-o
line-o requested review from a team and duncdrum July 4, 2026 12:56
@line-o line-o added xquery issue is related to xquery implementation needs develop port labels Jul 4, 2026
@line-o line-o changed the title Dev6 fix xslt imports Dev6 fix XSLT imports Jul 4, 2026
@line-o line-o changed the title Dev6 fix XSLT imports [Dev6] fix XSLT imports Jul 4, 2026
@line-o
line-o requested a review from wolfgangmm July 4, 2026 13:40
@line-o line-o self-assigned this Jul 4, 2026

@dizzzz dizzzz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM .

@duncdrum

duncdrum commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

@line-o we discovered a bug in izpack 5.2.3 during the beta release, not present in 5.2.2 if you have to downgrade we might want to go down two versions.

I m a bit at a loss how this pr relates to the in-flight upstream PRs touching upon this code area.

Comment thread exist-parent/pom.xml
<izpack.version>5.2.4</izpack.version>
<!-- NOTE: IzPack 5.2.4 pulls in radiance-theming 7.5.0 which requires Java 9+,
5.2.3 is the last release whose dependencies are all Java 8 compatible -->
<izpack.version>5.2.3</izpack.version>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@line-o line-o Jul 5, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will open an issue upstream

@line-o

line-o commented Jul 5, 2026

Copy link
Copy Markdown
Member Author

I m a bit at a loss how this pr relates to the in-flight upstream PRs touching upon this code area.

@duncdrum

  1. This targets develop-6.x.x to and aims to fix fn:transform for that branch
  2. Do you have a particular PR in mind I need to look at?

@line-o

line-o commented Jul 5, 2026

Copy link
Copy Markdown
Member Author

exist 6.4.1 was released with Izpack 5.2.3 -> I think you are referring to 5.2.5

@duncdrum

duncdrum commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

I mean #4957 and #6530. I mixed up izpack versions, 5.2.3 should work.

@line-o

line-o commented Jul 5, 2026

Copy link
Copy Markdown
Member Author

I also found your PRs #6530 and #6531 - I will also check #4957 but this is likely stale

@line-o

line-o commented Jul 5, 2026

Copy link
Copy Markdown
Member Author

I will base my forward port on #6531 @duncdrum alright?

@line-o

line-o commented Jul 5, 2026

Copy link
Copy Markdown
Member Author

#6531 adresses

✅ Compile-time URI resolution for xsl:import/xsl:include via URIResolution.CompileTimeURIResolver
✅ Saxon catalog resolver integration

Missing from #6531

❌ Runtime URI resolution for document() calls within the XSLT (at transform execution time)
❌ Fixes to Delivery.java for document builder handling
❌ Fixes to Convert.java for persistent node handling

What I will closely look at is the URI resolution logic in Options.java.

@duncdrum

duncdrum commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

@line-o however you want to thread the needle, the forward port will likely touch #5682 in addition to #5051.

line-o added a commit to line-o/exist that referenced this pull request Jul 5, 2026
… 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>
@line-o

line-o commented Jul 6, 2026

Copy link
Copy Markdown
Member Author

Develop port is #6546 @duncdrum let's move that discussion over there

@duncdrum duncdrum left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, one minor nitpick about the inlined xquery lines in fnTransform6065.xq,

"stylesheet-params": map {
xs:QName("v"): doc($t6065:collection || "/" || $t6065:source-doc-name)
}
(: ,"delivery-format": "serialized":)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dead code

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh right - leftovers from testing

@dizzzz
dizzzz merged commit 450f1fb into eXist-db:develop-6.x.x Jul 6, 2026
12 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

xquery issue is related to xquery implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants