The XSLT specification says that processors are not required to implement 
disable-output-escaping.  Xalan does, but if you ever want to output your 
transformation to a DOM tree (to be processed by another application) instead 
of a text file, then even Xalan won't support it.

There are some cases where you cannot avoid using disable-output-escaping, 
such as if you need to output some ASP/JSP code or similar.  But   has a 
simple alternative, which is  .

You can declare a DTD like this (at the very top of your xml file, right 
after the <?xml ...?>):

<!DOCTYPE xsl:stylesheet [
  <!ENTITY nbsp "&#160;">
]>

This DTD won't let you validate the stylesheet with a validating XML parser, 
because it doesn't declare any elements or attributes.  But it will declare 
the &nbsp; entity, which is fine for most purposes if you don't want to type 
&#160; directly.

To answer your other question, doing "<![CDATA[&nbsp;]]>" is the exact same 
thing as doing "&amp;nbsp;" (the CDATA section simply makes it so you don't 
have to escape the '&' and '<' characters).  So while CDATA is useful in many 
cases, using CDATA alone will not solve this problem.

One good discussion of this problem is at 
http://www.dpawson.co.uk/xsl/sect2/nbsp.html.  You can google for "xslt nbsp" 
and get about a hundred more such articles.

On Friday 08 February 2002 10:40, Beyer,Nathan wrote:
> Why is "disable-output-escaping" not guaranteed to work? I've never heard
> that before.
>
> I've never used a DTD with and XSLT file, how does that work?
>
> Also, couldn't I use a CDATA element instead? <![CDATA[&nbsp;]]>
>
> -----Original Message-----
> From: Peter Davis [mailto:[EMAIL PROTECTED]
> Sent: Friday, February 08, 2002 11:38 AM
> To: Beyer,Nathan
> Subject: Re: without escaping
>
>
> This is a very FAQ, and I hate to correct you since your answer will work
> in
>
> most cases, but the general concensus is that it is much better to use
> "&#160;" (which is the Unicode code for a non-breaking space).  This is
> because disable-output-escaping can be dangerous and is not guaranteed to
> work, especially if you ever output to a DOM tree.
>
> If your XSLT file has a DTD, you can do:
>
> <!ENTITY nbsp "&#160;">
>
> after which point you can use &nbsp; normally.
>
> The only problem with &#160; is that it shows up as a funky character in
> some
> situations (Internet Explorer with the default encodings), so I set my
> <xsl:output encoding="ISO-8859-1"/>
>
> On Friday 08 February 2002 08:45, Beyer,Nathan wrote:
> > You can do this:
> >
> > <xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>
> >
> > -----Original Message-----
> > From: Gubics Béla [mailto:[EMAIL PROTECTED]
> > Sent: Friday, February 08, 2002 10:40 AM
> > To: [EMAIL PROTECTED]
> > Subject: without escaping
> >
> >
> >
> > hi,
> >
> > how can i write in a xsl file "&nbsp;" if i want it in the result
> > unescaped...
> >
> > thanks
> >
> > gbk
> >
> >
> > CONFIDENTIALITY NOTICE
> >
> > This message and any included attachments are from Cerner Corporation and
> > are intended only for the addressee. The information contained in this
> > message is confidential and may constitute inside or non-public
>
> information
>
> > under international, federal, or state securities laws. Unauthorized
> > forwarding, printing, copying, distribution, or use of such information
> > is strictly prohibited and may be unlawful. If you are not the addressee,
> > please promptly delete this message and notify the sender of the delivery
> > error by e-mail or you may call Cerner's corporate offices in Kansas
> > City, Missouri, U.S.A at (+1) (816)221-1024.
> > -------------------------------------------

-- 
Peter Davis
Portability should be the default.
             -- Larry Wall in <[EMAIL PROTECTED]>

Reply via email to