Subject: Re: [xsl] Nesting a flat XML structure From: "Michael Kay mike@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Mon, 29 Oct 2018 18:40:15 -0000 |
You might like to read this paper, which tackles a similar problem. https://www.saxonica.com/papers/ideadb-1.1/mhk-paper.xml Michael Kay Saxonica > On 29 Oct 2018, at 18:14, ian.proudfoot@xxxxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote: > > Hello XSLT experts. > > I have a need to transform flat xml that was sourced from a word processor file and generate the implied structure. My efforts have been partially successful for one level nesting but Ibm finding it difficult to manage the process for an arbitrary number of nested levels. > > Herebs 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> > <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 Ibve got myself tied-up in knots trying to work out how to make it work for any further nesting. Perhaps Ibm overthinking it? I tried to create a recursive template to do the work, but thatbs where I got stuck. > > Ibm using the latest version of Saxon via the version 9 API. > > Thanks in advance. > Ian Proudfoot > Isle of Wight, UK > > > XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list> > EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/293509> (by email <>)
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Inline lists (was: Re: [xsl] Nestin, Peter Flynn peter@xx | Thread | Re: [xsl] Nesting a flat XML struct, Martin Honnen martin |
Re: [xsl] Nesting a flat XML struct, Martin Honnen martin | Date | Re: [xsl] Nesting a flat XML struct, Martin Honnen martin |
Month |