xsl-list
[Top] [All Lists]

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

2022-03-09 07:56:03
On Wed, Mar 09, 2022 at 01:43:44PM -0000, rick(_at_)rickquatro(_dot_)com 
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(_at_)gmail(_dot_)com
Þæs oferéode, ðisses swá mæg.
-- Deor  ("That passed, so may this.")
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>