xsl-list
[Top] [All Lists]

Re: [xsl] Sibling recursion?

2022-03-03 10:25:02
I would normally use xsl:iterate for this nowadays. Use `xsl:iterate 
select="node()"`, keep $pending-quote-content as a parameter; when processing 
each node, either append it to the content of $pending-quote-content for the 
next iteration, or flush $pending-quote-content to the output.

Michael Kay
Saxonica

On 3 Mar 2022, at 16:07, David Birnbaum djbpitt(_at_)gmail(_dot_)com 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

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 <http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/293509> (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>