I am using XSLT to remove unnecessary attributes from some nodes in a file. Nodes which should not be transformed use the following simple template:
<!-- Copy everything else over -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
However, I have found that some nodes are loosing escaped characters contained in their attribute values.
For example, this input:
<field value="Lei Complementar No. 116/2003, Art. 6, § 2º, I."/>
end up looking like this:
<field value="Lei Complementar No. 116/2003, Art. 6, § 2º, I."/>
How can I prevent this unwanted transformation?
I. XSLT 1.0 solution:
Just add this attribute to
xsl:output:This causes any non-ascii character to be rendered with its character code.
However, you may still get different outputs, such as:
and
And, of course, all of these three are just different represenatations of the same string of (unicode) characters.
II. XSLT 2.0 solution:
This uses the
<xsl:character-map>instruction and must always produce the same output:when this transformation is applied on the provided XML document:
the wanted, correct result is produced: