XSL transformation and special XML entities escaping
Posted
by
Tomas R
on Stack Overflow
See other posts from Stack Overflow
or by Tomas R
Published on 2009-12-16T14:56:12Z
Indexed on
2013/11/05
9:54 UTC
Read the original article
Hit count: 286
I have an XML file which is transformed with XSL. Some elements have to be changed, some have to be left as is - specifically, text with entities ", &, ', <, > should be left as is, and in my case " and ' are changed to " and ' accordingly.
Test XML:
<?xml version="1.0" encoding="UTF-8" ?>
<root>
<element>
"
&
'
<
>
</element>
</root>
transformation file:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" encoding="UTF-8" omit-xml-declaration="no" indent="no" />
<xsl:template match="element">
<xsl:copy>
<xsl:value-of disable-output-escaping="no" select="." />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
result:
<?xml version="1.0" encoding="UTF-8"?>
<element>
"
&
'
<
>
</element>
desired result:
<?xml version="1.0" encoding="UTF-8"?>
<element>
"
&
'
<
>
</element>
I have 2 questions:
- why does some of those entities are transformed and other not?
- how can I get a desired result?
© Stack Overflow or respective owner