[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: grouping problem

Subject: Re: grouping problem
From: "Imsieke, Gerrit, le-tex" <gerrit.imsieke@xxxxxxxxx>
Date: Fri, 16 Apr 2010 01:32:26 +0200
Re:  grouping problem
On 16.04.2010 00:50, Terry Ofner wrote:

I suspect that I should be using group-adjacent but am I unsure how to go ahead with such grouping in this case.


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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.