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

Re: xsl:for-each-group Problem

Subject: Re: xsl:for-each-group Problem
From: "Andrew Welch" <andrew.j.welch@xxxxxxxxx>
Date: Wed, 21 Nov 2007 13:22:42 +0000
Re:  xsl:for-each-group Problem
On 21/11/2007, Byomokesh Sahoo <sahoo.byomokesh@xxxxxxxxx> wrote:
> Hi All,
>
> I am facing xsl-for-each group problem in my Input xml file. Please
> see below my Input file.
>
> XML File
> ========
>
> <researcher>
> <title>Rethinking Foreign Policy</title>
> <question>Approach be abandoned?</question>
> <abstract>some Text</abstract>
> <section>Section The Issues</section>
> <para>some text</para>
> <section>Background</section>
> <para>some text</para>
> </researcher>
>
> I need ouput
> ============
>
> <researcher>
> <cover>
> <title>Rethinking Foreign Policy</title>
> <question>Approach be abandoned?</question>
> <abstract>some Text</abstract>
> </cover>
> <section label="the.issues">
> <section>Section The Issues</section>
> <para>some text</para>
> </section>
> <section label="Background">
> <section>Background</section>
> <para>some text</para>
> </section>
> </researcher>

Use:

    <xsl:template match="researcher">
        <xsl:for-each-group select="*" group-starting-with="section">
            <xsl:choose>
                <xsl:when test="current-group()[1][self::title]">
                    <cover>
                        <xsl:copy-of select="current-group()"/>
                    </cover>
                </xsl:when>
                <xsl:otherwise>
                    <section label="{.[self::section]}">
                        <xsl:copy-of select="current-group()"/>
                    </section>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:for-each-group>
    </xsl:template>

You'll need to sort out the label attribute to be how you want it, as
its not obvious from your example output.


cheers
-- 
Andrew Welch
http://andrewjwelch.com
Kernow: http://kernowforsaxon.sf.net/

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.