xsl-list
[Top] [All Lists]

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

2022-03-09 08:33:18
On Wed, Mar 09, 2022 at 01:58:37PM -0000, rick(_at_)rickquatro(_dot_)com 
scripsit:
I just want this: "This has text.”

Invert it:

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

and that element has a string property value where some characters
aren't XML whitespace (S ::= (#x20 | #x9 | #xD | #xA)+ so not space,
tab, carriage return, or line feed) AND that string property value has
at least one character that is NOT a member of Unicode character
category "Separators, spaces" so you won't pass through an element
containing one non-breaking space or one thin space or something. (You
will pass through a single period or a single colon or a single comma,
etc.)

If you're sure there are no fancy spaces in the input you only need the
normalize-space() predicate but I've had unfortunate experiences with
document content often enough to prefer both checks.

-- 
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>