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

Grouping paragraphs and sections in XSLT 2.0

Subject: Grouping paragraphs and sections in XSLT 2.0
From: <neil.crofts@xxxxxxxxxxxxxxxxxx>
Date: Thu, 8 Dec 2011 13:01:17 -0000
 Grouping paragraphs and sections in XSLT 2.0
Hi,

I've got some XML of the format shown below i.e. some number of
paragraphs followed by a section containing one or more paragraphs. This
pattern then repeats.

    <test>
        <paragraph id="a.1">a.one</paragraph>
        <paragraph id="a.2">a.two</paragraph>
        <paragraph id="a.3">a.three</paragraph>
        <section id="alpha">
            <paragraph id="alpha.1">one</paragraph>
            <paragraph id="alpha.2">two</paragraph>
            <paragraph id="alpha.3">three</paragraph>
        </section>
        <paragraph id="b.1">one</paragraph>
        <paragraph id="b.2">two</paragraph>
        <paragraph id="b.3">three</paragraph>
        <section id="beta">
            <paragraph id="beta.1">one</paragraph>
            <paragraph id="beta.2">two</paragraph>
            <paragraph id="beta.3">three</paragraph>
        </section>
        <paragraph id="b.1">one</paragraph>
        <paragraph id="b.2">two</paragraph>
        <paragraph id="b.3">three</paragraph>
    </test>

I need to be able to group the data as shown below - namely paragraphs
up until the next section in a separate group, followed by the section
in a separate group and then the pattern repeats :

<results>
    <GROUP>
        <paragraph id="a.1">a.one</paragraph>
        <paragraph id="a.2">a.two</paragraph>
        <paragraph id="a.3">a.three</paragraph>
    </GROUP>
    <GROUP>
        <section id="alpha">
            <paragraph id="alpha.1">one</paragraph>
            <paragraph id="alpha.2">two</paragraph>
            <paragraph id="alpha.3">three</paragraph>
        </section>
    </GROUP>
    <GROUP>
        <paragraph id="b.1">one</paragraph>
        <paragraph id="b.2">two</paragraph>
        <paragraph id="b.3">three</paragraph>
    </GROUP>
    <GROUP>
        <section id="beta">
            <paragraph id="beta.1">one</paragraph>
            <paragraph id="beta.2">two</paragraph>
            <paragraph id="beta.3">three</paragraph>
        </section>
    </GROUP>
    <GROUP>
        <paragraph id="b.1">one</paragraph>
        <paragraph id="b.2">two</paragraph>
        <paragraph id="b.3">three</paragraph>
    </GROUP>
</results>

My latest attempt is still not there:

    <xsl:template match="test">
        <xsl:for-each-group select="paragraph | section"
                            group-starting-with="section">
            <GROUP>
                <xsl:copy-of select="current-group()"/>

            </GROUP>
        </xsl:for-each-group>
    </xsl:template>

This results in the following, where the problem is that the paragraphs
following a section are included in that group. I'm not sure how to
correctly demark the end of a section so that it starts a new section
for the subsequent paragraphs.

<results>
    <GROUP>
        <paragraph id="a.1">a.one</paragraph>
        <paragraph id="a.2">a.two</paragraph>
        <paragraph id="a.3">a.three</paragraph>
    </GROUP>
    <GROUP>
        <section id="alpha">
            <paragraph id="alpha.1">one</paragraph>
            <paragraph id="alpha.2">two</paragraph>
            <paragraph id="alpha.3">three</paragraph>
        </section>

<!-- WANT THESE TO BE IN A NEW GROUP -->
        <paragraph id="b.1">one</paragraph>
        <paragraph id="b.2">two</paragraph>
        <paragraph id="b.3">three</paragraph>
    </GROUP>
    <GROUP>
        <section id="beta">
            <paragraph id="beta.1">one</paragraph>
            <paragraph id="beta.2">two</paragraph>
            <paragraph id="beta.3">three</paragraph>
        </section>

<!-- WANT THESE TO BE IN A NEW GROUP -->
        <paragraph id="b.1">one</paragraph>
        <paragraph id="b.2">two</paragraph>
        <paragraph id="b.3">three</paragraph>
    </GROUP>
</results>

Could anyone advise on a suitable approach for this problem? Thanks in
advance for any assistance.

Neil




This e-mail is for the sole use of the intended recipient and contains
information that may be privileged and/or confidential. If you are not an
intended recipient, please notify the sender by return e-mail and delete this
e-mail and any attachments. Certain required legal entity disclosures can be
accessed on our http://thomsonreuters.com/prof_disclosures.

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.