Re: [xsl] Novice Question - matching entire text children

Subject: Re: [xsl] Novice Question - matching entire text children
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Mon, 20 Dec 2010 18:33:45 -0500

On 12/20/2010 3:56 PM, David Lee wrote:
Some of both.   The generated XSLT is quite complicated (or atleast obtuse)
and my debugger wasn't giving me much help where the "\n   \n" was coming
So I tossed in a
	<xsl:strip-space elements="*"/>

And made some other changes which I've forgotten and now its not happening
anymore ...
So I guess I'm beyond it now :)

xsl:strip-space="*" is okay if you never have any mixed content, but it will let you down if you ever have source data like this:

<p>Here's some <i>italic</i> <b>and bold</b> together in a line</p>

The blank space between the </i> close tag and <b> open tag will be stripped. And of course any time you have mixed content, you have the potential for this.

Accordingly, it's wise to strip space only from elements that have element content, not #PCDATA or the equivalent in your favorite schema language, since by definition, whitespace occurring directly inside them is only cosmetic.

(Of course if your XSLT is generated out of an adequate schema, you should have that information available to you, at least in principle. Note also that XSLT 2.0 processors are allowed to consult a schema at tree-building time for warrant to strip insignificant whitespace like this.)

But the bit about PI's and comments breaking the text means I will still
need to revisit this.

Probably. It would be nice to avoid having to match on text nodes altogether -- and interesting to see the use case that would require it.


Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.      
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