Skip to content

[bugfix] fn:transform() now logs xsl:message output - #235

Open
Laurettta wants to merge 3 commits into
develop-7.x.xfrom
7.x.x/hotfix/xslt-messages-not-logged-fn-transform
Open

[bugfix] fn:transform() now logs xsl:message output#235
Laurettta wants to merge 3 commits into
develop-7.x.xfrom
7.x.x/hotfix/xslt-messages-not-logged-fn-transform

Conversation

@Laurettta

Copy link
Copy Markdown

We have registered a Saxon MessageListener on the Xslt30Transformer so xsl:message output now goes to the Elemental log instead of just printing to the console.

closes #234

Closes #234

We have registered a Saxon MessageListener on the Xslt30Transformer so xsl:message output now goes to the Elemental log instead of just printing to the console.
@cla-bot cla-bot Bot added the cla-signed label Aug 3, 2026
@codacy-production

Copy link
Copy Markdown

Not up to standards ⛔

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@Laurettta
Laurettta force-pushed the 7.x.x/hotfix/xslt-messages-not-logged-fn-transform branch from 408190a to 933b1be Compare August 4, 2026 08:48

final Xslt30Transformer xslt30Transformer = xsltExecutable.load30();

xslt30Transformer.setMessageListener((content, terminate, locator) ->{

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.

Can you please have this as a separate class at the bottom of the file rather than a large lambda here,

e.g.

private static class XsltMessageListener implements MessageListener {
...
}

import net.sf.saxon.s9api.*;
import net.sf.saxon.serialize.SerializationProperties;
import net.sf.saxon.trans.UncheckedXPathException;
import org.apache.commons.io.output.StringBuilderWriter;

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.

Just use java.io.StringWriter here please

serializer.setOutputWriter(writer);
serializer.serializeNode(content);

final String source;

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.

@Nullable final String source;

Import the annotation from googlecode findbugs library please

sourceColumn = -1;
}

LOGGER.info("<xsl:message terminate=\"{}\" source=\"{}\" sourceLine=\"{}\" sourceColumn=\"{}\">{}</xsl:message>",

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.

if source is null please don't print out the source= bit. Same goes for if sourceLine is -1 please don't print out the sourceLine and sourceColumn

final XQueryUtil.QueryResult queryResult = XQueryUtil.query(broker, new StringSource(query), false, null, null, null, null, null)) {
assertNotNull(queryResult.result);
} catch (final XPathException e) {
fail("Transform should have succeeded: " + e.getMessage());

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.

Just throw the exception from tests

fail("Transform should have succeeded: " + e.getMessage());
}

final Optional<String> logged = appender.getMessages().stream()

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.

we don't need Optional.

*/
private static class CapturingAppender extends AbstractAppender {

private final List<String> messages = new CopyOnWriteArrayList<>();

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.

Should not be CopyOnWriteArrayList

" \"stylesheet-text\": '<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"3.0\">\n" +
" <xsl:template match=\"/\">\n" +
" <xsl:message>Hello from XSLT</xsl:message>\n" +
" <out/>\n" +

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.

Why do we need this?

try {
final String query =
"fn:transform(map {\n" +
" \"stylesheet-text\": '<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"3.0\">\n" +

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.

version should be 2.0 not 3.0

final CapturingAppender appender = new CapturingAppender();
appender.start();

final org.apache.logging.log4j.core.Logger transformLogger =

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.

Fully qualified names hare are not needed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants