Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java: XSLT with output HTML but without HTML entities

Is it possible to to a XSL transformation mit xsl:output method set to HTML but without using HTML entities in the output? The output should either use numeric entities or no entities at all (as i am using UTF-8 entities are not required).

like image 642
Werzi2001 Avatar asked Feb 20 '26 17:02

Werzi2001


1 Answers

You can use disable-output-escaping. Using this input:

<test>Café</test>

with this XSL stylesheet:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="html" encoding="UTF-8"/>
    <xsl:template match="test">
        <xsl:copy>
            <xsl:value-of select="."/>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

will render:

<test>Caf&eacute;</test>

But if you add disable-output-escaping="yes" to <xsl:value-of>:

<xsl:value-of select="." disable-output-escaping="yes"/>

you get:

<test>Café</test>

You might also get unescaped HTML if you use a transformer that doesn't escape HTML by default, such as Saxon 9. I also believe you can configure Xalan to not escape HTML entities by default.

You can try a different transformer which disables output escaping by default.

like image 120
helderdarocha Avatar answered Feb 23 '26 07:02

helderdarocha