xsl-list
[Top] [All Lists]

Re: [xsl] Sibling recursion?

2022-03-03 10:24:55
On Thu, Mar 03, 2022 at 04:07:21PM -0000, David Birnbaum
djbpitt(_at_)gmail(_dot_)com scripsit:
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.

When I've had to do similar things (notably for hierarchy flattening),
I've used a recursive function, often with a "write out this accumulated
sequence of things which should be wrapped or otherwise together" helper
function.

This function gets called on the sequence of nodes found in each p
element, and contains a choose which starts with "input sequence empty?
stack empty?" and "input sequence empty, still stuff in the stack?"
tests and then starts doing specific things. (For example, your "this is
a whitespace only text node" case would throw that node away.)

This uses head() and tail() a lot and I find it starts off feeling
incomprehensible and then abruptly makes sense.  It's also easy to
extend if new elements show up in later versions of the content.

If that doesn't make sense I can dig up an example.

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