Re: [xsl] Sibling recursion?

Subject: Re: [xsl] Sibling recursion?
From: "Eliot Kimber eliot.kimber@xxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 3 Mar 2022 16:09:54 -0000
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@xxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thursday, March 3, 2022 at 10:07 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
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!Vd7vk09Z65Lg2I5TtV92mX6oej7lH7Qigm33qUMG4BjFOF8zXzTsj4fkw4iNPW
k2tbmj9Q$>
EasyUnsubscribe<https://urldefense.com/v3/__http:/lists.mulberrytech.com/unsu
b/xsl-list/3453418__;!!N4vogdjhuJM!Vd7vk09Z65Lg2I5TtV92mX6oej7lH7Qigm33qUMG4B
jFOF8zXzTsj4fkw4iNPWntdDya4w$> (by email<>)

Current Thread