1

When using the org.apache.xalan.xsltc.trax.TransformerFactoryImpl XSLT transformer factory, the URI mapped to a prefix gets lost when the result tree is saved in a variable.

Consider the following namespace.xsl XSLT :

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

    <xsl:template match="/node">
        <xsl:variable name="Var">
            <xsl:apply-templates select="body"/>
        </xsl:variable>
        <xsl:copy-of select="$Var" />
    </xsl:template>

    <xsl:template name="wrap" match="body">
        <xsl:comment><xsl:value-of select="system-property('xsl:vendor')" />(<xsl:value-of select="system-property('xsl:version')" />)[<xsl:value-of select="system-property('xsl:vendor-url')" />]</xsl:comment>
        <html>
            <xsl:copy-of select="." />
        </html>
    </xsl:template>
</xsl:stylesheet>

With the following namespace.xml input

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?xml-stylesheet type="text/xsl" href="namespace.xsl"?>

<node xmlns:html="http://www.w3.org/1999/xhtml">
    <body>
        <html:h1 html:align="center">
            Hallo
        </html:h1>
    </body>
</node>

The result is

<?xml version="1.0" encoding="UTF-8"?><!--Apache Software Foundation (Xalan 
    XSLTC)(1.0)[http://xml.apache.org/xalan-j] -->
<html xmlns:html="http://www.w3.org/1999/xhtml">
    <body>

        <h1 xmlns:html="html" html:align="center">
            Hallo
        </h1>

    </body>
</html>

Please note the fact that h1 has no prefix and inside the prefix html is assigned to the uri "html".

When I set the transformfactory to 'org.apache.xalan.processor.TransformerFactoryImpl' everything works as expected and I get the following result:

<?xml version="1.0" encoding="UTF-8"?><!--Apache Software Foundation(1.0)[http://xml.apache.org/xalan-j] -->
<html xmlns:html="http://www.w3.org/1999/xhtml">
    <body>
        <html:h1 html:align="center">
            Hallo
        </html:h1>

    </body>
</html>

I can't find any known issues regarding this, does anyone know what I am doing wrong here?

The following Java code is used to run the transformatin:

System.setProperty("javax.xml.transform.TransformerFactory", "org.apache.xalan.xsltc.trax.TransformerFactoryImpl");
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer(new StreamSource("namespace.xsl"));
transformer.transform(new StreamSource("namespace.xml"), new StreamResult(new FileOutputStream("namespace_out.xml")));

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.