This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Keeping "&" in xml data when parsed


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

Cheers,

Tom P



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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]