Re:[xsl] semi-newbie question about escaping

Subject: Re:[xsl] semi-newbie question about escaping
From: Joseph Kesselman <keshlam@xxxxxxxxxx>
Date: Tue, 15 Oct 2002 13:14:49 -0400
>The goal here was to output some non-breaking space entities in HTML 
>(&nbsp;) to denote indentation.

The &nbsp; entity isn't defined by default in XML. Your stylesheet needs 
to reference a DTD, or set up an internal subset, which provides that 

Alternatively, as others have said, use the numeric character reference 
rather than the mnemonic entity name. That should work everywhere &nbsp; 
does, and doesn't have to be explicitly defined.

Either way, if you can get the character into the data in the first place, 
HTML output mode will convert it to &nbsp; on output. XML output mode may 
or may not do so, depending on whether you specified a DTD reference for 
the output and on the exact behavior of your XSLT processor's serializer; 
most won't, but I think it's allowed to do so if it wants to make the 
additional effort.

And either is better than trying to construct the entity reference as 
text. Among other things, if you ever want to pipe the XSLT processor's 
output directly into another XML application you'll find that the text 
approach will come through as text (equivalent to &amp;nbsp;) whereas the 
character reference or the properly-defined entity reference will come 
through as the intended character.

Joe Kesselman  / IBM Research

 XSL-List info and archive:

Current Thread