|
Subject: [xsl] Grouping paragraphs and sections in XSLT 2.0 From: <neil.crofts@xxxxxxxxxxxxxxxxxx> Date: Thu, 8 Dec 2011 13:01:17 -0000 |
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 |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| RE: [xsl] layout problem, Roelof Wobben | Thread | Re: [xsl] Grouping paragraphs and s, Martin Honnen |
| [xsl] Re: [Bulk] Re: [xsl] XPath "v, Anthony B. Coates (X | Date | Re: [xsl] Grouping paragraphs and s, Martin Honnen |
| Month |