RE: [xsl] Inserting White Space (  ) through XSL.

Subject: RE: [xsl] Inserting White Space (  ) through XSL.
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Mon, 03 May 2004 15:24:13 -0400
Animesh,

At 03:44 AM 5/3/2004, you wrote:
Quoted from some Site:
Empty cells in tables often cause problems to HTML authors, especially since browsers often display such cells without border even if the other cells have borders. There is an often-mentioned trick to solve that problem: put &nbsp; into an empty cell.

What Some Site isn't telling you is why this works.


It works because "&_nbsp;" (no underscore) is a general entity in HTML, which represents a particular Unicode character, the non-breaking space, which combines two necessary features. First, since it is not a regular whitespace character (in HTML these are the carriage return, the tab and the regular space characters), it is not "munged" or collapsed in the display. This is what accounts for the border on a table cell in which this character appears alone. (If you have only a plain space, your border doesn't appear, which is why there's a problem in the first place.) But just as importantly, unlike other characters that count as non-whitespace content, this character *looks like* space.

This character can be represented straightforwardly in XML using a Unicode character reference for its code point: &_#xA0; (if you like hexadecimal numbering) or &_#160; (if you prefer decimal numbering) -- both times with no underscore character in there (if I type them properly at least some people's mailers will say "oh a non-breaking space", and display them as spaces).

Going by above quotation I tried getting &nbsp; in the output. And I got that using using <xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>.
But again another problem pop up because output generated is Not a well-formed XML as & get inserted in the output. And I cann't attach More XSL to the output generated.

You can use the &_nbsp; general entity in well-formed XML if you declare it (you would provide a declaration to tell your system that when you say "&_nbsp;" you mean "&_#160;"), but XSLT 1.0 has no provision for providing such declarations in output.


May be I have to find some alternative solution for the above problem.

The alternative solution would be simply to use the straight character reference instead of the general entity. That is -- as has been suggested -- you use &_#160; instead of the error-prone workaround using disable-output-escaping.


Many of us do this routinely, so we know it works. Anyone who tells us that it doesn't has a little explaining to do. If & # 1 6 0 ; doesn't work for you, you're doing something else wrong, or your situation is different from the general case in some important but unspecified way.

I hope that helps,
Wendell




====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================

Current Thread