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

Re: Using xsl:for-each-group to create nested sections

Subject: Re: Using xsl:for-each-group to create nested sections
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Fri, 9 Jul 2004 22:14:33 +0100
xsl for each group
Hi Renee,

> How can I get the stylesheet to wrap the nested section tags only
> around the content beginning with the first <h2> and not around the
> elements that come before the first <h2>?

Add a test to see whether the current node (which is the first node in
a particular group) is an <h2> element or not; if it is, then create
the <section> element; if it isn't, then don't:

<xsl:template match="doc">
  <doc>
    <xsl:for-each-group select="*" group-starting-with="h1">
      <section>
        <xsl:apply-templates select="current-group()[self::h1]" />
        <xsl:for-each-group select="current-group() except ."
                            group-starting-with="h2">
          <xsl:choose>
            <xsl:when test="self::h2">
              <section>
                <xsl:apply-templates
                  select="current-group()[self::*]" />
              </section>
            </xsl:when>
            <xsl:otherwise>
              <xsl:apply-templates
                select="current-group()[self::*]" />
            </xsl:otherwise>
          </xsl:choose>
        </xsl:for-each-group>
      </section>
    </xsl:for-each-group>
  </doc>
</xsl:template>

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/

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.