Re: [xsl] nbsp and copy-of and output xml

Subject: Re: [xsl] nbsp and copy-of and output xml
From: "Andrew Welch" <andrew.j.welch@xxxxxxxxx>
Date: Mon, 18 Aug 2008 10:00:16 +0100
> WHAT I WANT TO PRODUCE: &nbsp; WITH copy-of with output method="xml"

The short answer is "you can't" - but there's usually no need to.

The XSLT processor operates on an input tree.  That tree is built by
the XML parser, which when it encounters the entity "nbsp" (or any
entity) it will expand it to the value that entity represents... #160
in this case.  So when the XSLT processor gets involved, there is no
nsbp to copy, just it's expanded value #160.  The XSLT has no idea
whether that value came from entity expansion, or was written directly
in the XML.

The usual reason people want nbsp in their output is because #160 is a
2 byte character in UTF-8 and results in spurious characters appearing
in the output, like a-with-circumflex.  This is simply an encoding
issue, and well worth understanding and fixing.  Outputting #160 is
the right thing to do, if its highlighting an encoding problem then
fix that rather than hack an nbsp into the output (which sadly seems
to be nearly always the route chosen).

If you really do need to output entity references, I've (almost)
written a small utility which converts lexical events into markup,
such as entity references and cdata sections, so you would get:

<lexev:entity name="nbsp"> </lexex:entity>

(which the space is the expanded value of #160)

...which is then easy to process with XSLT.



-- 
Andrew Welch
http://andrewjwelch.com
Kernow: http://kernowforsaxon.sf.net/

Current Thread