Re: [xsl] for-each-group for multiple nodes

Subject: Re: [xsl] for-each-group for multiple nodes
From: "C. M. Sperberg-McQueen" <cmsmcq@xxxxxxxxxxxxxxxxx>
Date: Mon, 20 Jul 2009 13:50:11 -0600
On 17 Jul 2009, at 03:36 , Ramkumar wrote:

...
I am not able to achieve my expected output through for-each-group for
multiple nodes in a single template match. Please look into my detailed
inputs and find mistakes in my below code.
...
xslt
=====
...


<xsl:template match="book">
<book>
 <xsl:for-each-group select="*"
group-starting-with="para[contains(@aid:pstyle,'Level')]">

If the sample input you showed is typical, this is equivalent to

<xsl:for-each-group select="*" group-starting-with="para"/>

I think that since you want each LevelF para to generate a
distinct qandaset element in the output, you might think
about whether you really want a distinct group for every
para, or just a distinct group for every sequence of elements
beginning with para aid:pstyle="LevelF".



  <xsl:choose>
	    <xsl:when test="self::para/@aid:pstyle[contains(.,'LevelF')]">
	     <qandaset>
	      <xsl:call-template name="g">
	       <xsl:with-param name="e" select="current-group()"/>
	      </xsl:call-template>
	     </qandaset>
	    </xsl:when>

The code above seems to expect that the current-group() will contain the following LevelM and LevelM_sub para elements. It won't: each time the input contains a new para element with contains(@aid:pstyle,'Level'), a new group will be started. So your Level M paragraphs and their subordinate parts will be in the next group, not this one.

As a first step, try to get the outermost grouping to work;
don't worry about the inner groupings.  Since you want
each LevelF paragraph to produce an element containing its
following siblings up to but not including the next level
F paragraph, you want a grouping based on the LevelF value,
not on the string 'Level'.

Within those groups, you may want to make use of recursive
groupings for Level M.

I hope this helps; if it does not help sufficiently, please ask
again.

Michael Sperberg-McQueen

--
****************************************************************
* C. M. Sperberg-McQueen, Black Mesa Technologies LLC
* http://www.blackmesatech.com
* http://cmsmcq.com/mib
* http://balisage.net
****************************************************************

Current Thread