This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: & converted to &
- From: Jeni Tennison <jeni at jenitennison dot com>
- To: hlgoh at jobstreet dot com (Goh Hong Ling)
- Cc: "Xsl-List at Lists dot Mulberrytech. Com" <xsl-list at lists dot mulberrytech dot com>
- Date: Fri, 28 Jun 2002 13:53:16 +0100
- Subject: Re: [xsl] & converted to &
- Organization: Jeni Tennison Consulting Ltd
- References: <HAECJFEPGCNFFOKFNDBGCELECDAA.hlgoh@jobstreet.com>
- Reply-to: xsl-list at lists dot mulberrytech dot com
Hai Hong Ling,
> In my XSLT file, I want to convert a code to a description. The
> description somehow might contains &, < and > symbols. The
> description will display as a plaintext. In my XSL file, I set
>
> <xsl:when test=" code='13' ">AI & </xsl:when>
> <xsl:when test=" code='14' ">£</xsl:when>
When the XML parser parses the XSLT stylesheet, it creates a tree that
looks like:
xsl:when ----- test: code='13'
+- "AI & "
xsl:when ----- test: code='14'
+- "£"
As far as XSLT is concerned, there is absolutely no difference between
using '&' in your stylesheet and using '&' in your stylesheet
-- they are both decoded into the character '&'.
When you serialise that as XML, the & character has to be escaped
because the & is a significant character in XML (it marks the start of
an entity reference or character reference). The built-in escape for
the & character is '&', so that's the one that most processors use
to serialise & characters.
If you're generating plain text rather than XML, then you should set
the output method to text using the xsl:output element:
<xsl:output method="text" />
That way the processor won't do any escaping (there are no special
characters in plain text), and you'll get the characters '&' and '£'
in your output.
If you want to generate XML, but have more control over how the result
tree is serialised, then put the result of the transforming into a DOM
and write your own processor to serialise that DOM as an XML document.
By the way, the reason that your browser is displaying '&' and '£', as
it should, is that it knows that the entity reference '&' means
the character '&', so that's what it displays.
Cheers,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list