[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: grouping problem
On 16.04.2010 00:50, Terry Ofner wrote:
Spring time is grouping time on this list, so it seems. You are right, group-adjacent is your friend, but not alone: consider the case that two question/choice blocks are immediately adjacent. Then group-adjacent won't seperate them at each block's question line, but instead will put them all together. So I suggest to use group-starting-with with a group-adjacent applied to each primary group (in order to filter out the non-question paras). Or you could do it the other way round: perform a group-adjacent on the boolean condition that there is question/choice content, then group the groups where current-grouping-key() is true, starting at each question. Here's a sample stylesheet for the first solution: ======8<----------------------------- <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" > <xsl:output method="xml" indent="yes" /> <xsl:template match="testbody"> <testbody> <xsl:for-each-group select="*" group-starting-with="p[ @class=( 'bodytext-question', 'bodytext-questionfirst' ) ]"> <xsl:choose> <!-- Don't consider the first group if it starts with something else: --> <xsl:when test="self::p[ @class=( 'bodytext-question', 'bodytext-questionfirst' ) ]"> <xsl:for-each-group select="current-group()" group-adjacent="boolean( self::p[ @class=( 'bodytext-question', 'bodytext-questionfirst', 'bodytext-choice' ) ] )"> <xsl:choose> <xsl:when test="current-grouping-key()"> <xsl:element name="question"> <xsl:apply-templates select="current-group()"/> </xsl:element> </xsl:when> <xsl:otherwise> <xsl:apply-templates select="current-group()"/> </xsl:otherwise> </xsl:choose> </xsl:for-each-group> </xsl:when> <xsl:otherwise> <xsl:apply-templates select="current-group()"/> </xsl:otherwise> </xsl:choose> </xsl:for-each-group> </testbody> </xsl:template> <xsl:template match="@* | *"> <xsl:copy> <xsl:apply-templates select="@* | node()" /> </xsl:copy> </xsl:template> </xsl:stylesheet> ======8<----------------------------- Gerrit
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|