[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Whitespace between nodes

Subject: RE: Whitespace between nodes
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Thu, 13 May 2004 09:26:06 +0100
xsl remove whitespace
> As a further illustration: as it happens your XSL code is the same as
> <q>
>   <xsl:choose>
>     <xsl:when test="@href != ''">
>       <a href="{@href}">...</a>
>     </xsl:when>
>   ...
>   </xsl:choose>
> </q>
> Would you agree that, in this case, it should be:
> <q>
>   <a href="...">...</a>
> </q>
> ?

Assuming that the output method is HTML, the output should be

<q><a href="...">...</a></q>

whether or not indent="yes" has been set.

This is because of the rule (from XSLT 1.0 section 16.2) that: "If the
indent attribute has the value yes, then the html output method may add or
remove whitespace as it outputs the result tree, so long as it does not
change how an HTML user agent would render the output. The default value is

The XSLT 2.0 Serialization spec retains this rule and gives implementations
additional guidance on its implications. See section 6.3 of  


"Whitespace must not be added or removed adjacent to an inline element. The
inline elements are those included in the %inline category of any of the
HTML 4.01 DTD's, as well as the INS and DEL elements if they are used as
inline elements (i.e., if they do not contain element children)."

The <a> element is an inline element, so the whitespace above should not
have been added.

However, as far as I can see the responses to the original question have
been very confused. I don't think it has been clearly established whether
the unwanted whitespace came (a) from whitespace-only text nodes in the
source (in which case it should be removed using xsl:strip-space), (b) from
significant whitespace in the source (in which case it should be removed
using normalize-space()), or (c) as a result of output indentation. The
remedies in the three cases are quite different.

Michael Kay 

Michael Kay

Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.