Subject: Re: [xsl] Sibling recursion? From: "David Carlisle d.p.carlisle@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Thu, 3 Mar 2022 16:31:14 -0000 |
would I be thrown off xsl-list for suggesting sed? $ sed -e 's@</q>\(\s*\)<q>@ @g' q.xml <x> <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> </x> On Thu, 3 Mar 2022 at 16:07, David Birnbaum djbpitt@xxxxxxxxx < xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> 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/2739265> (by > email <>)
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Sibling recursion?, Michael Kay mike@xxx | Thread | Re: [xsl] Sibling recursion?, Michael Kay mike@xxx |
Re: [xsl] Sibling recursion?, Michael Kay mike@xxx | Date | Re: [xsl] Sibling recursion?, Michael Kay mike@xxx |
Month |