Re: [xsl] xslt 2.0: grouping flat element structures to make lists

Subject: Re: [xsl] xslt 2.0: grouping flat element structures to make lists
From: David Carlisle <davidc@xxxxxxxxx>
Date: Thu, 26 May 2005 10:20:56 +0100
  Thanks for the solution David Carlisle, this certainly does the
  flat-to-grouped job I need. 


It's missing a template to map  <par class="Listitem"> yo <item> of
course in the version I posted.


  However, one more query (open to anyone): Would I need to add this grouping
  processing approach to ALL the possible parent elements that the flat-list
  structures can occur in? 


Yes, no, or maybe.


Plan (a) would be to replace 

<xsl:template match="sect">

by

<xsl:template match="*[par/@class='Listitem']">

so you do this for all elements that have a list in them.

The problem is what is "this" I was using xsl:copy but if you need to
transform the diferent elements in different ways than copy isn't what
you want so thi splan forks into

plan a.a)
To it in two passes, first do an identity transform plus this grouping
catching the result into a temporary tree in a variable, then apply your
original templates to this variable.

plan a.b)
Do it in one pass, but instead of calling xsl:copy while doing the
grouping, call  a named template or template in some special mode, or
something that does whatever is needed in the way of a transform.


Or you could decide to do

plan b) Don't use for-each group at all.
 just have your normal transformation templates, then add a template

<xsl:template match="par[@class='Listitem']"/>

so all list items go in the main run

and have a template

<xsl:template match="par[@class='Listbegin']">
that starts a <list> and grabs all the following items, something like


<xsl:template match="par[@class='Listbegin']">
<list>
<xsl:apply-templates mode="l" select="following-sibling::*[1]"/>
</list>
</xsl:template>

<xsl:template mode="l" match="par[@class='Listitem']">
<item><xsl:apply-templates/></xsl:item>
<xsl:apply-templates mode="l" select="following-sibling::*[1]"/>
</xsl:template>


<xsl:template mode="l" match="*"/>


Actually I was going to use plan (b) in my first reply, but then I
noticed that you said you wanted to use XSLT 2 grouping constructs
and plan b isn't very good as a teach-yourself-xslt2 example, as it's
xslt1:-)


David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

Current Thread