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

Subject: Re: [xsl] Creating a complex hierarchical structure from flat strcuture
From: David Carlisle <davidc@xxxxxxxxx>
Date: Fri, 16 Mar 2007 13:53:18 GMT
> 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

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


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


Current Thread