Re: [xsl] Convert text nodes to a single string

Subject: Re: [xsl] Convert text nodes to a single string
From: "Graydon graydon@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 9 Mar 2022 13:55:59 -0000
On Wed, Mar 09, 2022 at 01:43:44PM -0000, rick@xxxxxxxxxxxxxx scripsit:
> Thank you Martin and Wendell.  I am incorporating this one:
> 
> normalize-space(string-join(text()))=''

elementName[not(normalize-space())] will be true in boolean context if
there are no non-whitespace text nodes contributing to the string value
of the element.

This is dangerous in some document content because someone will have
used fancy spaces, such as U+00A0, "NO BREAK SPACE", which is not
to normalize-space() a space.

elementName[not(matches(.,'\P{Zs}`))] will be true in boolean context if
there's something in the string property of the element which is NOT a
member of the "Separators, spaces" Unicode character category.

Stack them:

elementName[not(normalize-space())][not(matches(.,'\P{Zs}'))]

and you're reasonably safe from non-breaking spaces, thin spaces, etc.
foiling your test.  elementName can safely be considered to not have any
words in it.


-- 
Graydon Saunders  | graydonish@xxxxxxxxx
^fs oferiode, pisses swa mfg.
-- Deor  ("That passed, so may this.")

Current Thread