xsl-list
[Top] [All Lists]

RE: [xsl] Newbie Question: Convert "flat" hierarchy to nested hierarchy

2006-10-14 08:58:47
You'll find a paper that tackles this problem (using XSLT 2.0) at

http://www.idealliance.org/proceedings/xml04/papers/111/mhk-paper.html

The reverse transformation is much easier: you just process all the elements
in document order (//nest) and for each one compute its level number as
count(ancestor::*).

Michael Kay
http://www.saxonica.com/
 

-----Original Message-----
From: Watch-O-Matic [mailto:watchomatic(_at_)fastmail(_dot_)fm] 
Sent: 14 October 2006 16:09
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Newbie Question: Convert "flat" hierarchy to 
nested hierarchy

I'm a newbie among newbies in XSLT, so I request your patience.

I'm interested in knowing if I can write an XSLT to transform a "flat"
hierarchy, representing the hierarchy of a document, into a 
true nested hierarchy. And do the reverse direction transformation.

To illustrate, here's an example of a "flat" hierarchy, where 
the hierachical level of each {markupx} item is specified 
using the 'lvl' attribute. (Each {markupx} item contains a 
mix of marked-up
content.)

   <flat lvl="1"> {markupA} </flat>
   <flat lvl="2"> {markupB} </flat>
   <flat lvl="2"> {markupC} </flat>
   <flat lvl="1"> {markupD} </flat>
   <flat lvl="2"> {markupE} </flat>
   <flat lvl="2"> {markupF} </flat>
   <flat lvl="3"> {markupG} </flat>
   <flat lvl="4"> {markupH} </flat>
   <flat lvl="4"> {markupI} </flat>
   <flat lvl="3"> {markupJ} </flat>
   <flat lvl="3"> {markupK} </flat>
   <flat lvl="2"> {markupL} </flat>
   <flat lvl="1"> {markupM} </flat>


Here's what I'd like to transform it into, and back again:

   <nest> {markupA}
      <nest> {markupB} </nest>
      <nest> {markupC} </nest>
   </nest>
   <nest> {markupD}
      <nest> {markupE} </nest>
      <nest> {markupF}
         <nest> {markupG}
            <nest> {markupH} </nest>
            <nest> {markupI} </nest>
         </nest>
         <nest> {markupJ} </nest>
         <nest> {markupK} </nest>
      </nest>
      <nest> {markupL} </nest>
   </nest>
   <nest> {markupM} </nest>


Assume also that there will be other shared attributes for 
both <flat> and <nest> -- I've left them out in the above 
markup examples to make it easier to visualize the problem.


Are the two-way transformations doable in XSLT?

I humbly request the discussion focus on the feasibility of 
the two-way transformation, and not on alternatives to the 
markup models I'm working with. I don't have much say in the 
matter since this task was dropped in my lap (and having to 
come up to speed in XSLT.)

Thanks!

Mark
--
  Watch-O-Matic
  watchomatic(_at_)fastmail(_dot_)fm

--
http://www.fastmail.fm - Same, same, but different.


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--