Project

Profile

Help

Bug #4403

closed

Internal error when calling saxon:transform() with stylesheet without primary output

Added by Johan Gheys over 4 years ago. Updated almost 2 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Saxon extensions
Sprint/Milestone:
Start date:
2019-12-04
Due date:
% Done:

100%

Estimated time:
Legacy ID:
Applies to branch:
9.9, trunk
Fix Committed on Branch:
9.9, trunk
Fixed in Maintenance Release:
Platforms:

Description

For the moment, we chain multiple transformations together by using the standard transform() function without any problems (see the simplified example 1 in attached zip). In order to reduce memory consumption, we like to replace this function by the saxon:transform() extension function allowing the secondary result output to be serialized directly to filestore. When the styleheet has no primary output, we get the following error (see example 2):

java.lang.RuntimeException: Internal error evaluating function shared:transform-with-saxon at line 162 in module file:/D:/Data/MyProjects/upp/upm-publish-processing/src/test/saxon-transform/xsl/shared-functions.xslt at net.sf.saxon.expr.instruct.UserFunction.call(UserFunction.java:612)...

Putting a dummy element in the primary result tree, solves the problem.


Files

saxon-transform.zip (538 KB) saxon-transform.zip Johan Gheys, 2019-12-04 10:53
saxon-config.xml (387 Bytes) saxon-config.xml Johan Gheys, 2022-02-21 09:53
Actions #1

Updated by Michael Kay over 4 years ago

saxon:transform() is pretty ancient and rather reflects the old XSLT 1.0 processing model where there is always one source document. Have you considered using the standard XSLT 3.0 fn:transform() function instead, which is much more flexible?

Of course we should fix any crash.

One word of caution about chaining transformations in this way: because you're invoking one transformation before the other has finished, it can be heavy on memory use (the internal state of the first transformation, including the source document tree, is there for the duration of the second, even if it is never going to be used again). Piping the results of one transformation to another using SAX-like events, e.g. at the s9api level using one XsltTransformer as the destination of another, is potentially more efficient.

Actions #2

Updated by Johan Gheys over 4 years ago

We use the standard XSLT 3.0 fn:transform () function already as much as possible (see example 1), but this function has no parameter to directly write secondary result documents to the filestore. Such documents are accumulated in memory together with the primary output document, after which writing can only begin. This means a considerable memory consumption, especially when it concerns a large number of documents with a large volume. In these specific cases we hope to be able to use the saxon:transform () function so that the secondary output can be serialized directly to the filestore.

Actions #3

Updated by Michael Kay over 4 years ago

Thanks, that's useful feedback.

The specification of result document handling in fn:transform() was a significant challenge because the WG didn't want to define some half-baked side-effect mechanism; delegating the disposal of secondary result documents to a user-written function was a way of basically offloading the problem onto implementors, who presumably already have their own workarounds for handling calls to external functions with side effects.

Actions #4

Updated by Johan Gheys over 4 years ago

Thank you for the clarifying background information. I understand that an additional parameter would not be a good solution. Hopefully we can still count on a well-functioning saxon:transform() function in the future.

Actions #5

Updated by Johan Gheys over 4 years ago

Small additional question: when using the standard XSLT 3.0 fn:transform() function with the additional option source-location provided by Saxon, we notice a different behavior compared to the stylesheet-location option. The stylesheet-location option seems to use the standard URIResolver; the source-location option not. The documentation doesn't mention any different behavior. What are the rules to correctly use the source-location option?

Actions #6

Updated by Michael Kay about 4 years ago

Sorry for the delay in progressing this.

There were various paths in which the implementation of the call() method was returning null rather than an EmptySequence, which is incorrect. The documentation also needs to be updated to indicate that saxon:transform() can return an empty sequence if the stylesheet generates no principal output.

Actions #7

Updated by Michael Kay about 4 years ago

  • Category set to Saxon extensions
  • Status changed from New to In Progress
  • Assignee set to Michael Kay
  • Applies to branch 9.9, trunk added
  • Fix Committed on Branch 9.9, trunk added

Code patched on 9.9 and trunk: TransformFn.call() returns ZeroOrOne rather than NodeInfo, and returns empty sequence instead of null when there is no result. Function signature updated to make the result optional. Documentation updated on trunk only.

Actions #8

Updated by Michael Kay about 4 years ago

  • Status changed from In Progress to Resolved

As regards fn:transform and source-location, yes, I think we should be using the URIResolver. A more significant omission is that we don't seem to be setting the base URI for resolving a relative source-location, which means it's going to resolve against the current directory rather than the static base URI. I have fixed both these issues.

Actions #9

Updated by Johan Gheys about 4 years ago

No problem for the delay. Your support is always appreciated.

Actions #10

Updated by O'Neil Delpratt about 4 years ago

  • Status changed from Resolved to Closed
  • % Done changed from 0 to 100
  • Fixed in Maintenance Release 9.9.1.7 added

Patch applied in the 9.9.1.7 maintenance release.

Actions #11

Updated by Johan Gheys about 2 years ago

The problem is back in version 11.2:

D:\Data\MyProjects\upmb\upm-batch\src\test\resources\saxon\saxon-transform>java -jar D:\Data\MyProjects\upmb\upm-batch\src\test\lib\saxon-ee-11.2.jar -xsl:xsl/batch-with-saxon.xslt -config:config/saxon-config.xml -it !method=text 
Launching remove-past-versions.xslt
	parameter file-names=ptcar region
	parameter purge-date=2019-12-01
	parameter xml-folder=D:/Data/MyProjects/upmb/upm-batch/src/test/resources/saxon/saxon-transform/xml/
java.lang.RuntimeException: Internal error evaluating function shared:transform-with-saxon at line 171 in module file:/D:/Data/MyProjects/upmb/upm-batch/src/test/resources/saxon/saxon-transform/xsl/shared-functions.xslt
	at net.sf.saxon.expr.instruct.UserFunction.call(UserFunction.java:660)
	at net.sf.saxon.expr.UserFunctionCall.callFunction(UserFunctionCall.java:555)
	at net.sf.saxon.expr.UserFunctionCall.evaluateItem(UserFunctionCall.java:487)
	at net.sf.saxon.expr.parser.Evaluator$SingleItem.evaluate(Evaluator.java:179)
	at net.sf.saxon.expr.parser.Evaluator$SingleItem.evaluate(Evaluator.java:167)
	at net.sf.saxon.expr.instruct.WithParam.getSelectValue(WithParam.java:317)
	at net.sf.saxon.expr.instruct.Instruction.assembleParams(Instruction.java:204)
	at net.sf.saxon.expr.instruct.CallTemplate.processLeavingTail(CallTemplate.java:429)
	at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:755)
	at net.sf.saxon.expr.instruct.NamedTemplate.expand(NamedTemplate.java:266)
	at net.sf.saxon.expr.instruct.CallTemplate$CallTemplatePackage.processLeavingTail(CallTemplate.java:561)
	at net.sf.saxon.expr.instruct.CallTemplate.process(CallTemplate.java:386)
	at net.sf.saxon.expr.instruct.CallTemplate.processLeavingTail(CallTemplate.java:446)
	at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:755)
	at net.sf.saxon.expr.instruct.NamedTemplate.expand(NamedTemplate.java:266)
	at net.sf.saxon.trans.XsltController.callTemplate(XsltController.java:873)
	at net.sf.saxon.s9api.Xslt30Transformer.callTemplate(Xslt30Transformer.java:483)
	at net.sf.saxon.Transform.processFile(Transform.java:1380)
	at net.sf.saxon.Transform.doTransform(Transform.java:869)
	at net.sf.saxon.Transform.main(Transform.java:81)
Actions #12

Updated by Michael Kay about 2 years ago

You seem to have introduced a configuration file that's not present in the original repro, so I'm having trouble running this.

Actions #13

Updated by Johan Gheys about 2 years ago

Sorry, I thought all the files had been uploaded last time.

Actions #14

Updated by Johan Gheys almost 2 years ago

The command line option -config:config/saxon-config.xml can even be deleted as it is not needed to reproduce the problem. We hope the solution to this problem will be available soon so that we can switch to Saxon version 11.x.

Please register to edit this issue

Also available in: Atom PDF