tags:

views:

796

answers:

3

How can I insert

 

Into an XSLT stylesheet, I keep getting this error:

XML Parsing Error: undefined entity

Essentially I want a non breaking space character in the XSLT Template.

+7  A: 

Try using the entity   instead.

More details on why   doesn't work and other options here.

Brabster
Great, exactly what I needed....
JL
+1 and there's always the possibility to declary nbsp entity too.
Michael Krelin - hacker
+1  A: 

Use this

<xsl:text disable-output-escaping="yes">&amp;</xsl:text>nbsp;

edit: Downvoters should probably validate that this works first (it does, and is the most general solution to the problem.)

jagprinderdeep
nbsp is not explicitly encoded space.
Michael Krelin - hacker
never said it was
jagprinderdeep
I am worried about my mental condition. I'm pretty sure I've commented on the answer saying something like "why not use CDATA instead of explicitly encoding space". I do not see a trace of it, but I still have a morsel of confidence. Tell me, have you gone completely mad?
Michael Krelin - hacker
Not sure, but i've tested my approach and it works, so i'm not certain what the downvote was for :(
jagprinderdeep
Also, the accepted answer will not be valid for all parsers according to the linked page; just a heads up
jagprinderdeep
Downvoters, please give reasons
jagprinderdeep
*Crickets*--------
jagprinderdeep
I've given the reason for my downvote before, but if I were to downvote *this* answer, then the reason would be - it answers the wrong question. The OP clearly asked how to put in nonbreakable space, using xslt and you answered how to put ampersand-n-b-s-p-semicolon sequence. And quarreling over downvotes is unnice too.But seriously, have you never ever said that about CDATA?
Michael Krelin - hacker
Never mentioned CDATA
jagprinderdeep
Okay, jagprinderdeep, I revoke my downvote, but in return please go visit me once I hit the mental asylum. (note that I don't give you the downvote back for that new reason). But do understand that you answer the wrong question. I think that was exactly the reason behind the other downvote.
Michael Krelin - hacker
@jagprinderdeep, searched for letterly like a week for a solution for adding a space. NOTHING WORKED!! But your solution worked! Thanks! I upvoted.
Yustme
+2  A: 

You might want to add the definition for this entity in the beginning of the file (below xml declaration):

<!DOCTYPE stylesheet [
<!ENTITY nbsp  "&#160;" >
]>

Also you can add more entities such as Ntilde, Aacute, etc.

victor hugo