Re: [xsl] XSLT splitting (grouping?) hierarchical structure

Subject: Re: [xsl] XSLT splitting (grouping?) hierarchical structure
From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 10 Feb 2022 08:54:00 -0000
Am 10.02.2022 um 09:40 schrieb Imsieke, Gerrit, le-tex
gerrit.imsieke@xxxxxxxxx:
Hi Matthieu,

At XML Prague 2019, I presented what I call the "upward projection
method" [1, 2]. It turned out that Wendell Piez had independently
developed his own upward projection approach [3, 4]. Both methods
group the leaf nodes, starting at the splitting points.

Gerrit

[1]

https://archive.xmlprague.cz/2019/files/xmlprague-2019-proceedings.pdf#page=3
47
[2]

https://subversion.le-tex.de/common/presentations/2019-02-09_xmlprague_xslt-u
pward-projection/slides/index.html


I think Gerrit's approach will help you although I think your set of restricted-to nodes will be adapted slightly, instead of

B B current-group()/ancestor-or-self::node()

it seems you want to carry over the section/title from each section.

[3]
https://github.com/wendellpiez/MITH_XSLT/blob/master/xslt/p-promote.xsl
[4]

https://www.biglist.com/lists/lists.mulberrytech.com/xsl-list/archives/202008
/msg00076.html


On 10.02.2022 09:20, Matthieu Ricaud-Dussarget ricaudm@xxxxxxxxx wrote:
Dear XSL List,

It's not the first time I'm facing a splittingB problem working with
publishing documents.
I used to findB kind of tricky/verbose solutions but I'm wondering if
I'm missing something obvious, especially with XSLT 3.0 new features ?

My XML looks like this :
<root>
B B  <section>
B B  B  <title>Title</title>
B B  B  <content>
B B  B  B  <p>paragraph #1</p>
B B  B  B  <p>paragraph #2 to split <split id="split-1"/> here</p>
B B  B  B  <p>paragraph #3</p>
B B  B  B  <p>paragraph #4 <strong> to split <split id="split-2"/>
here</strong> if possible</p>
B B  B  B  <p>paragraph #5</p>
B B  B  B  <ul>
B B  B  B  B  <li>Item #1</li>
B B  B  B  B  <li>Item #2 to split <split id="split-3"/> here</li>
B B  B  B  B  <li>Item #3</li>
B B  B  B  B  <li>
B B  B  B  B  B  <ul>
B B  B  B  B  B  B  <li>Item #4</li>
B B  B  B  B  B  B  <li>Item #5 to <em>split <split id="split-4"/></em>
here
if possible</li>
B B  B  B  B  B  B  <li>Item #6</li>
B B  B  B  B  B  </ul>
B B  B  B  B  </li>
B B  B  B  </ul>
B B  B  B  <p>paragraph #6</p>
B B  B  </content>
B B  </section>
</root>

The goal is to split the section on every <split> element (just like
a page would break the flowing text anywhere in the structure).

Expected result :
<root>
B B  B  <section>
B B  B  B  <title>Title</title>
B B  B  B  <content>
B B  B  B  B  <p>paragraph #1</p>
B B  B  B  B  <p>paragraph #2 to split</p>
B B  B  B  </content>
B B  B  </section>
B B  B  <split id="split-1"/>
B B  B  <section>
B B  B  B  <title>Title</title>
B B  B  B  <content>
B B  B  B  B  <p>paragraph #3</p>
B B  B  B  B  <p>paragraph #4 <strong> to split</strong></p>
B B  B  B  </content>
B B  B  </section>
B B  B  <split id="split-2"/>
B B  B  <section>
B B  B  B  <title>Title</title>
B B  B  B  <content>
B B  B  B  B  <p><strong> here</strong> if possible</p>
B B  B  B  B  <p>paragraph #5</p>
B B  B  B  B  <ul>
B B  B  B  B  B  <li>Item #1</li>
B B  B  B  B  B  <li>Item #2 to split </li>
B B  B  B  B  </ul>
B B  B  B  </content>
B B  B  </section>
B B  B  <split id="split-3"/>
B B  B  <section>
B B  B  B  <title>Title</title>
B B  B  B  <content>
B B  B  B  B  <ul>
B B  B  B  B  B  <li> here</li>
B B  B  B  B  B  <li>Item #3</li>
B B  B  B  B  B  <li>
B B  B  B  B  B  B  <ul>
B B  B  B  B  B  B  B  <li>Item #4</li>
B B  B  B  B  B  B  B  <li>Item #5 to <em>split</em></li>
B B  B  B  B  B  B  </ul>
B B  B  B  B  B  </li>
B B  B  B  B  </ul>
B B  B  B  </content>
B B  B  </section>
B B  B  <split id="split-4"/>
B B  B  <section>
B B  B  B  <title>Title</title>
B B  B  B  <content>
B B  B  B  B  <ul>
B B  B  B  B  B  <ul>
B B  B  B  B  B  B  <li> here if possible</li>
B B  B  B  B  B  </ul>
B B  B  B  B  B  <li>Item #6</li>
B B  B  B  B  </ul>
B B  B  B  B  <p>paragraph #6</p>
B B  B  B  </content>
B B  B  </section>
B B  </root>

My idea was to iterate from 1 to the number of split elementsB + 1 and
working on the section with tunnel params so I can test for each node
if it's before / after / in betweenB (current) splits elements, and
then decide to keep the node or not according to this position.

I already used this kind of solution on a similar problem, long time
ago. So I'll give it a try thoughB I'm not not totally confident with
it (because split elements can appear as inline content here).

Please let me know if you have ideas, if my solution is the right or
wrong way to go?
Are there special design patterns for this kind of problem ?
And last, haveB you ever faced this kind of splittingB issue, any
feedbackB welcome :)

Cheers,
Matthieu Ricaud-Dussarget

Current Thread