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

Re: Nesting a flat XML structure

Subject: Re: Nesting a flat XML structure
From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 29 Oct 2018 18:28:44 -0000
Re:  Nesting a flat XML structure
On 29.10.2018 19:14, ian.proudfoot@xxxxxxxxxxx wrote:

Heres a much simplified, but representative example of typical source XML:

<doc>

<p style="h1">title text</p>

<p style="para">body text</p>

<p style="para">body text</p>

<p style="bullet_level1">list text</p>

<p style="bullet_level1">list text</p>

<p style="bullet_level2">list text</p>

<p style="bullet_level2">list text</p>

<p style="bullet_level2">list text</p>

<p style="h2">title text</p>

<p style="para">body text</p>

<p style="para">body text</p>

</doc>

I need to generate the nested structure to look like similar to this (again much simplified):

<doc>

<section>

<title>title text</title>

<p>body text</p>

<p>body text <ul>


Why is the "ul" a child of the "p" element?

<li>list text</li>

<li>list text<ul>

<li>list text</li>

<li>list text</li>

<li>list text</li>

</ul>

</li>

</ul>

</p>

<section>

<title>title text</title>

<p>body text</p>

<p>body text</p>

</section>

</section>

</doc>

There is no way to know in advance the level of nesting that may be needed. The rules for nesting are provided by a separate mapping file. The mapping file is used as the input to generate a document specific xslt file that handles element naming and adds all of the necessary attributes. The format and content of that mapping file are under my control but the source documents are not.

My initial efforts used xsl:for-each-group with group adjacent to identify and nest the first level and that works nicely, but Ive got myself tied-up in knots trying to work out how to make it work for any further nesting. Perhaps Im overthinking it? I tried to create a recursive template to do the work, but thats where I got stuck.

It might help if you show us the first level grouping that does the right job.


It seems you need to combine two approaches, one to recursively group and wrap sections based on the 'p style="hn"' (which I think can be done with "group-starting-with"), the other based on "group-adjacent" for list items.

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.