RE: [xsl] XML apparently cannot be used for general text markup: whitespace gripe

Subject: RE: [xsl] XML apparently cannot be used for general text markup: whitespace gripe
From: "Andy Joslin" <andy.joslin@xxxxxxxx>
Date: Wed, 20 Mar 2002 09:57:27 -0000
When I first came to XSL, one of my immediate concerns was how to get what I would call 'good practice' (x)html in the result document after the transformation. As most client-side developers know, browsers can be more than a little unforgiving with bad html output (extra space in table cells can cause them to break, and the opposite, one huge block of text, can cause certain browsers to fail to render properly).

The solution/workaround that I've arrived at (and thanks in most part to suggestions from this list) are to do some or all of the following:

1. Strip all unwanted whitespace nodes from the source document using xsl:strip-space.

2. Don't rely on the XSL processor to indent the html, set the output method indent to "no".

3. Use xml:space="preserve" on your templates where you want the code you write to be output as you intended it.

4. Be wary of whitespace creeping back in through xsl:variables, etc. where the whitespace within these elements can be copied to the result.

5. If you can, try and ensure that the XML that is being generated is as tidy as possible, and that other developers are aware that whitespace is an issue. (At the end of the day, presented with the choice of either using a function such as xsl:normalize-space or simply asking another developer to be careful with their code, I know what I'd rather do.)

cheers

Andy


From: Hunsberger, Peter
>As I've watched this forum I've noticed a lot of questions on how to get
>precise HTML output (e.g.. &nbsp; ad nauseam).  I think somehow the
>community needs more emphasis on how to do XML to HTML with CSS and on how
>to do XML --> XHTML --> HTML.  It's probably something that should be
>emphasized in the books and FAQs?  
-------------------------------------------
From: Wendell Piez
>At root, I think we see this problem as an expression of the Worlds in 
>Collision represented by XML: on the data side, people are used to throwing 
>in whitespace wherever, just to make the source code readable (which in 
>principle is a good thing); whereas on the document side, white space has 
>to be regarded as part of our source data since we simply have no way of 
>knowing when it's not. In other words, whitespace is both, or either, data 
>content, or "just markup" -- as it always has been.

>But I'd be interested in what others have to say about this.

This e-mail and its attachments are confidential. If you are not the intended recipient of this e-mail message, please telephone or e-mail us immediately, delete this message from your system and do not read, copy, distribute, disclose or otherwise use this e-mail message and any attachments. 

Although RI3K Limited believes this e-mail and any attachments to be free of any virus or other defect which may affect your computer, it is the responsibility of the recipient to ensure that it is virus free and RI3K Limited does not accept any responsibility for any loss or damage in any way from its use.

RI3K Limited
Registered in England: 10-12 Ely Place, London, EC1N 6RY
Company Number: 3909745

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


Current Thread