xsl-list
[Top] [All Lists]

Re: [xsl] Sibling recursion?

2022-03-03 10:10:00
My initial thought is that xsl:iterate might do what you want in a clearer way.

Cheers,

E.

_____________________________________________
Eliot Kimber
Sr Staff Content Engineer
O: 512 554 9368
M: 512 554 9368
servicenow.com<https://www.servicenow.com>
LinkedIn<https://www.linkedin.com/company/servicenow> | 
Twitter<https://twitter.com/servicenow> | 
YouTube<https://www.youtube.com/user/servicenowinc> | 
Facebook<https://www.facebook.com/servicenow>

From: David Birnbaum djbpitt(_at_)gmail(_dot_)com 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com>
Date: Thursday, March 3, 2022 at 10:07 AM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com 
<xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Subject: [xsl] Sibling recursion?
[External Email]

Dear XSL-list,

I recently used sibling recursion to manage an XSLT transformation and I would 
be grateful for advice about whether there is a more legible and maintainable 
alternative. I'm using XSLT 3.0. The task was:

My input is <p> elements with mixed content, some of which is <q> elements (and 
other element types). Consecutive <q> elements inside a <p> should be merged 
into a single <q>, where consecutive means either immediately following (with 
no intervening nodes) or with an intervening whitespace-only text node. For 
example:

<p><q>Merge me with the next quote</q><q>I immediately follow the quote I 
should be merged with</q> and now some plain text <q>merge me with the next 
quote, too</q> <q>but this time there is a whitespace-only text node between 
us</q></p>

The desired output is:
<p><q>Merge me with the next quote I immediately follow the quote I should be 
merged with</q> and now some plain text <q>merge me with the next quote, too 
but this time there is a whitespace-only text node between us</q></p>

There could be other elements inside the mixed content, some inside the quotes 
and some not. Quotes do not nest inside other quotes and they have to be merged 
with other quotes only inside the same paragraph (that is, not across paragraph 
boundaries).

The sibling-recursion approach works as required, but it feels cumbersome even 
after I made an intermediate pass to remove whitespace-only text nodes between 
<q> elements, so that they would be immediate following sibling nodes, which 
freed me from having to distinguish whitespace-only text nodes from other text 
nodes when I merged the quotes.

I would be grateful for any insights.

Best,

David
XSL-List info and 
archive<https://urldefense.com/v3/__http:/www.mulberrytech.com/xsl/xsl-list__;!!N4vogdjhuJM!Vd7vk09Z65Lg2I5TtV92mX6oej7lH7Qigm33qUMG4BjFOF8zXzTsj4fkw4iNPWk2tbmj9Q$>
EasyUnsubscribe<https://urldefense.com/v3/__http:/lists.mulberrytech.com/unsub/xsl-list/3453418__;!!N4vogdjhuJM!Vd7vk09Z65Lg2I5TtV92mX6oej7lH7Qigm33qUMG4BjFOF8zXzTsj4fkw4iNPWntdDya4w$>
 (by email<>)
--~----------------------------------------------------------------
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>