This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Keeping "&" in xml data when parsed
- From: "Thomas B. Passin" <tpassin at mitretek dot org>
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Fri, 25 Jan 2002 10:38:21 -0500
- Subject: Re: [xsl] Keeping "&" in xml data when parsed
- References: <4.3.2.7.2.20020125144621.036eee70@pop0.goodtechnology.net>
- Reply-to: xsl-list at lists dot mulberrytech dot com
[James Knight]
>
> My database is pulling out a company name, "A & B", and writing it into an
> xml file.
> When I try to parse the xml through a stylesheet, I get a complaint that
> the entity name must follow the ampersand immediately, i.e. the parser
> thinks it's a mis-typed entity.
>
> Bearing in mind that I don't have access to the database, is there any way
> to warn the stylesheet not to attempt to translate the ampersand?
>
>
You have to escape the ampersand with & or the string (or ampersand)
has to be in a CDATA section. Otherwise it's not well-formed xml and won't
get past the parser. The CDATA section is one way to tell the parser that
you mean the character literally (there's no way to "warn the stylesheet",
since the character has been dealt with before the xslt processor ever sees
it).
You can alter the query. For example, the query could read something like
select '<![CDATA[' + name + ']]>' as escaped_name from company
Without a way to change the query, you have to preprocess the results,
replacing each "&" with "&".
Cheers,
Tom P
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list