Re: [xsl] Resend: Is there a way ...

Subject: Re: [xsl] Resend: Is there a way ...
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Wed, 14 Mar 2001 08:52:38 +0000
Hi Allen,

> My stylesheet converts from XML to XML, changing values or
> structure. For most part it just copies what's in the input XML to
> the output XML.
>
> But if the input has
> & apos ; (&apos;)
> or
> & quot ; (&quot;)
> , the output changes them to
> '        ( ' )
> and
> & # 34 ; (&#34;)
> , which is not good. I'd like to preserve what was in the input. Is
> there a way to do that?

You shouldn't care about whether the escaped version of a character is
used or not.  The processor will usually not output the escaped
version of a character unless it has to, but it makes no difference in
terms of the XML information that the file contains.

If you are really desperate to have these characters escaped, then you
could write a search and replace function that searches for
apostrophes and double quotes and replaces them with the relevant
general entity with output escaping disabled:

  <xsl:text disable-output-escaping="yes">&apos;</xsl:text>

However, this will only work for element content, not for attribute
values (and I think that it's attribute values you're having a problem
with, since otherwise the double quote wouldn't be being escaped).

So the only way around it within the styleheet is to use the text
output method and output the XML in the way that you want it
outputted.  That means you can't use things like literal result
elements, xsl:element, xsl:attribute, xsl:copy or xsl:copy-of to get
your output - you have to write it all by hand.

Or you could write your own output serialiser for Saxon that escaped
everything in the way you want it escaped.

Or you could write a post-processor in Perl or something that searched
and replaced all occurrences of those characters in the file.

So there are ways, but I doubt it's worth the hassle.

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread