[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

XSLT splitting (grouping?) hierarchical structure

Subject: XSLT splitting (grouping?) hierarchical structure
From: "Matthieu Ricaud-Dussarget ricaudm@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 10 Feb 2022 08:20:35 -0000
 XSLT splitting (grouping?) hierarchical structure
Dear XSL List,

It's not the first time I'm facing a splitting problem working with
publishing documents.
I used to find 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>
  <section>
    <title>Title</title>
    <content>
      <p>paragraph #1</p>
      <p>paragraph #2 to split <split id="split-1"/> here</p>
      <p>paragraph #3</p>
      <p>paragraph #4 <strong> to split <split id="split-2"/> here</strong>
if possible</p>
      <p>paragraph #5</p>
      <ul>
        <li>Item #1</li>
        <li>Item #2 to split <split id="split-3"/> here</li>
        <li>Item #3</li>
        <li>
          <ul>
            <li>Item #4</li>
            <li>Item #5 to <em>split <split id="split-4"/></em> here if
possible</li>
            <li>Item #6</li>
          </ul>
        </li>
      </ul>
      <p>paragraph #6</p>
    </content>
  </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>
    <section>
      <title>Title</title>
      <content>
        <p>paragraph #1</p>
        <p>paragraph #2 to split</p>
      </content>
    </section>
    <split id="split-1"/>
    <section>
      <title>Title</title>
      <content>
        <p>paragraph #3</p>
        <p>paragraph #4 <strong> to split</strong></p>
      </content>
    </section>
    <split id="split-2"/>
    <section>
      <title>Title</title>
      <content>
        <p><strong> here</strong> if possible</p>
        <p>paragraph #5</p>
        <ul>
          <li>Item #1</li>
          <li>Item #2 to split </li>
        </ul>
      </content>
    </section>
    <split id="split-3"/>
    <section>
      <title>Title</title>
      <content>
        <ul>
          <li> here</li>
          <li>Item #3</li>
          <li>
            <ul>
              <li>Item #4</li>
              <li>Item #5 to <em>split</em></li>
            </ul>
          </li>
        </ul>
      </content>
    </section>
    <split id="split-4"/>
    <section>
      <title>Title</title>
      <content>
        <ul>
          <ul>
            <li> here if possible</li>
          </ul>
          <li>Item #6</li>
        </ul>
        <p>paragraph #6</p>
      </content>
    </section>
  </root>

My idea was to iterate from 1 to the number of split elements + 1 and
working on the section with tunnel params so I can test for each node if
it's before / after / in between (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 though 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, have you ever faced this kind of splitting issue, any
feedback welcome :)

Cheers,
Matthieu Ricaud-Dussarget

-- 
Matthieu Ricaud-Dussarget
+33 6.63.25.95.58

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.