xsl-list
[Top] [All Lists]

Re: [xsl] (Re-)Escaping entities in input text

2008-08-20 09:21:46
Of course, there is the possibility of replacing all 5 entities "by hand" by 
calling a transform function, however this might not be very efficient when 
the string is getting big. Is there either:

_never_ do that... it's the first step down the wrong road which is
long and painful.

- a way of disabling entity interpretation with xsl:value-of (actually 
getting "<" when it's written like this in the input file)

xsl:value-of simply creates text nodes in the result tree, there is no
interpretation going on - that only happens during
parsing/serialisation

- a function to "reescape" a piece of text so that it's usable in an XML 
file/string?

that happens during serialisation... for example:

<foo> a &lt; b </foo>

when that's parsed you will get a node "foo" with a single text node
child "a < b".   If you do xsl:value-of on that text node, it will add
to the result tree.  It's still "a < b" at this point.  Then the
serializer operates on the result tree which knows that "<" in a text
node must be escaped, so after that step it becomes "a &lt; b"...

It sounds like you might be skipping the serialization step - perhaps
you're constructing a String and just writing that to disk?  eg

String xml = "<foo>" + someValue = "</foo>";

...which would give you:

<foo> a < b </foo>.

...hence the question?  Doing it that way is A Bad Thing - the golden
rule is to always read and write XML using proper XML readers and
writers.

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

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--