xsl-list
[Top] [All Lists]

Re: [xsl] Creating a complex hierarchical structure from flat strcuture

2007-03-16 06:53:52

However, i'm not sure upto what level my hierarchy is there a more 
general or better way to do this?

it's a bit tricky (perhaps) to be fully general as both your input and
output is using the more rigid form with level-specific names like
subsection2para (on input) and subsection2 (on output). rather than just
using generic names and letting the level being implied by the hierarchy
(which typically makes it easier to share code between levels).

Hoewever if that's the way the elemnt names have to be, so be it.

I would work in two stages, first remove the hard coded element names
by some code that generates them based on a level parameter, ie replace


  <subsection2>
  <xsl:for-each-group  select="current-group()"
... (@class, 'subsection[3]para', 

by

<xsl:variable name="l" select="2"/>
  <xsl:element name="subsection{$l}">
  <xsl:for-each-group  select="current-group()"
... (@class, concat('subsection[',$l+1,']para'), 

...

then once that's working, you may well find that the code you have for
each level can be placed in a template with a l parameter that can just
call itself wil l set to $l+1 if there are any non-empty groups to
process, which would alow you to refactor and share the code for each
group level.


David

--~------------------------------------------------------------------
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>
--~--

<Prev in Thread] Current Thread [Next in Thread>