質問

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).

役に立ちましたか?

解決

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top