xsl-list
[Top] [All Lists]

RE: [xsl] grouping problem

2010-04-15 18:04:30
Here is the basic grouping 2.0 template (xsl:attribute 
elements have been removed) in which I am trying to group the 
@class='bodytext- question and @class=bodytext-choice elements:

  <xsl:template match="testbody">
           <testbody>
                <xsl:for-each-group select="*" 
group-starting-with="p 
[(_at_)class=('bodytext-question','bodytext-questionfirst')]">

This template works for bodytext-questions that are followed 
by other bodytext-questions. But it also groups everything 
from the start of <testbody> to the first bodytext-question 
as well as everything that follows the last of a series of 
bodytext-questions.

Every node selected by select="*" will end up in exactly one group. 

For the nodes preceding the first "matching" node, the usual strategy is to
ungroup them again (or to do some other special processing on them)
typically by testing within xsl:for-each-group whether the first item in the
group does indeed match the group-starting-with pattern. As for "everything
that follows the last of a series of bodytext-questions", it's not clear to
me from your example what this means, but the last group is going to take in
everything from the last bodytext-question to the end, and you're going to
have to include logic to break it up if necessary.

I don't know whether this works in your case, but one technique of course is
to replace select="*" by a more specific select that only contains the nodes
you want in the output.

Regards,

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


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