Re: [xsl] Keeping "&" in xml data when parsed

Subject: Re: [xsl] Keeping "&" in xml data when parsed
From: "Thomas B. Passin" <tpassin@xxxxxxxxxxxx>
Date: Fri, 25 Jan 2002 10:38:21 -0500
[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 &amp;  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

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 "&amp;".


Tom P

 XSL-List info and archive:

Current Thread