Re: [xsl] 0x19 is not a legal XML character

Subject: Re: [xsl] 0x19 is not a legal XML character
From: Abel Braaksma <>
Date: Thu, 28 Jun 2007 13:28:28 +0200
Michael Kay wrote:
Of course, it can be valid content, in which case the XML documents should be opened as XML 1.1 documents.

I'm reluctant to join a thread that has been deemed by both the OP and Tommie to be off-topic, but in the interests of accuracy: x19 is a legal character in XML 1.1 only if written in the form of a numeric character reference. (Which means that encoding is definitely NOT an issue).

Aha, I forgot about that... This explains why the file *can* be read with unparsed-text *and* the 1.1 option set, and *cannot* be read as XML input document.

This also means that, if you have no control on the input and these characters are not escaped as num char ref, then one could write a filter app in XSLT like this:

<xsl:output method="text" use-character-maps="char-to-ent" />

<xsl:character-map name="char-to-ent">
   <xsl:output-character character="&#x16;" string="&amp;#x16;"/>
   <xsl:output-character character="&#x17;" string="&amp;#x17;"/>
   <xsl:output-character character="&#x18;" string="&amp;#x18;"/>
   <xsl:output-character character="&#x19;" string="&amp;#x19;"/>

<xsl:template match="/" name="main">
   <xsl:value-of select="unparsed-text('make-control-chars.xml')" />

But, of course, like Andrew pointed out, this is not the best way to go (though it is not uncommon in large systems to have data filtered before it reaches your application, and XLST can do quite a good job there).

-- Abel

Current Thread