Mike Dee
Mike Dee

Reputation: 580

Strange XSLT transformation

I've just observed something strange regarding an XSLT transform I've done many times.

We have a standalone java app that creates reports. Report data is read out of a database, converted to XML, and then transformed to display the data in different ways.

A simple transform produces text output but the text being produced is in decimal encoded ASCII!!! I simplified the transform to this to try and isolate the problem:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:output method="text"/>
<xsl:preserve-space elements="*"/>

<xsl:template match="/">
    <xsl:text>Hello World</xsl:text>
</xsl:template>

</xsl:stylesheet>   

And the output is this:

&#72;&#101;&#108;&#108;&#111;&#32;&#87;&#111;&#114;&#108;&#100; 

I have never seen this before!

This same transformation is performed in our webapp (on the same server) and it works fine, producing: Hello World.

There are a couple of things different in this environment. First we are running on Windows Server 2022 with Java 11. We haven't run before on this version of Windows nor in Java 11.

Has anyone seen anything like this before?

MORE: This is how we perform the XSLT transformation. Note that this same code runs in our webapp and works fine but in the standalone java app it produced the output above.

public String transform( String xml, String xslTemplate )
{       
    TransformerFactory tFactory = TransformerFactory.newInstance();
    Transformer transformer = tFactory.newTransformer(
        new StreamSource( xslTemplate ) );
            
    transformer.setOutputProperty( 
        javax.xml.transform.OutputKeys.ENCODING, "iso-8859-1" );

    StringReader input = new StringReader( xml );
    
    ByteArrayOutputStream b = new ByteArrayOutputStream();
    transformer.transform( new StreamSource( input ), new StreamResult( b ) );
    
    out = b.toString( "iso-8859-1" );

    return out;
}

Upvotes: 0

Views: 25

Answers (0)

Related Questions