This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: Is this about grouping ?
- To: mail at jenitennison dot com
- Subject: RE: [xsl] Is this about grouping ?
- From: Benoit_Aumars at jltgroup dot com
- Date: Tue, 3 Jul 2001 10:09:12 +0100
- Cc: XSL-List at lists dot mulberrytech dot com
- Reply-To: xsl-list at lists dot mulberrytech dot com
Jeni,
Thanks for your help.
But I still have a little problem in the transformation.
The original source, as Rick Suiter suggests ( thanks again Rick ) is as
follow :
<?xml version="1.0"?>
<topic>
<group>
<a>ItemA</a>
<b>ItemB</b>
<f>111</f>
<g>Alpha</g>
<h>text3</h>
<i>text4</i>
</group>
<group>
<a>ItemA</a>
<b>ItemB</b>
<f>222</f>
<g>Bravo</g>
<h>text7</h>
<i>text8</i>
</group>
<group>
<a>ItemA</a>
<b>ItemB</b>
<f>333</f>
<g>Charlie</g>
<h>text11</h>
<i>text12</i>
</group>
</topic>
And here the XSL as you suggests ( after modification ) :
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" indent="yes" omit-xml-declaration="no" />
<xsl:key name="groups" match="group" use="concat(a,':',b)"/>
<xsl:template match="topic">
<topic>
<xsl:apply-templates select="group[generate-id() =
generate-id(key('groups',concat(a,':',b))[1])]"/>
</topic>
</xsl:template>
<xsl:template match="group">
<RqUID><xsl:value-of select="a"/></RqUID>
<SDR><xsl:value-of select="b"/></SDR>
<Contact>
<ContactLine>
<xsl:variable name="elements"
select="key('groups',concat(a,':',b))"/>
<xsl:for-each select="$elements">
<Detail>
<Name><xsl:value-of
select="concat($elements/*/following-sibling::f[1]
,$elements/*/following-sibling::g[1])"/></Name>
<Reference><xsl:value-of
select="$elements/*/following-sibling::h[1]"/></Reference>
</Detail>
<Info><xsl:value-of
select="$elements/*/following-sibling::i[1]"/></Info>
</xsl:for-each>
</ContactLine>
</Contact>
</xsl:template>
</xsl:transform>
And here the result :
<?xml version="1.0" encoding="UTF-8"?>
<topic>
<RqUID>ItemA</RqUID>
<SDR>ItemB</SDR>
<Contact>
<ContactLine>
<Detail>
<Name>111Alpha</Name>
<Reference>text3</Reference>
</Detail>
<Info>text4</Info>
<Detail>
<Name>111Alpha</Name>
<Reference>text3</Reference>
</Detail>
<Info>text4</Info>
<Detail>
<Name>111Alpha</Name>
<Reference>text3</Reference>
</Detail>
<Info>text4</Info>
</ContactLine>
</Contact>
</topic>
Questions :
1. what's wrong with the 'following-sibling::' above ? I would expect this
result ( in simplified ) :
<Name>111Aplha</Name>
<Name>222Bravo</Name>
<Name>333Charlie</Name>
2. the issues about indentation is shown in that result. I think for better
readability ,it would
be much better if the result is as follow :
<?xml version="1.0" encoding="UTF-8"?>
<topic>
<RqUID>ItemA</RqUID>
<SDR>ItemB</SDR>
<Contact>
<ContactLine>
<Detail>
<Name>111Alpha</Name>
<Reference>text3</Reference>
</Detail>
<Info>text4</Info>
<Detail>
<Name>111Alpha</Name>
<Reference>text3</Reference>
</Detail>
<Info>text4</Info>
<Detail>
<Name>111Alpha</Name>
<Reference>text3</Reference>
</Detail>
<Info>text4</Info>
</ContactLine>
</Contact>
</topic>
Would you be able to help me out ?
Thanks,
Benoit Aumars.
************************************************************
JLT Management Services Limited
6 Crutched Friars, London EC3N 2PH. Co Reg No 1536540
Tel: (44) (0)20 7528 4000 Fax: (44) (0)20 7528 4500
http://www.jltgroup.com
------------------------------------------------------------
The content of this e-mail (including any attachments) as
received may not be the same as sent. If you consider that
the content is material to the formation or performance of
a contract or you are otherwise relying upon its accuracy,
you should consider requesting a copy be sent by facsimile
or normal mail. The information in this e-mail is
confidential and may be legally privileged. If you are not
the intended recipient, please notify the sender immediately
and then delete this e-mail entirely - you must not retain,
copy, distribute or use this e-mail for any purpose or
disclose any of its content to others.
Opinions, conclusions and other information in this e-mail
that do not relate to the official business of JLT
Management Services Limited shall be understood as neither
given nor endorsed by it. Please note we intercept and
monitor incoming / outgoing e-mail and therefore you should
neither expect nor intend any e-mail to be private in nature.
We have checked this e-mail for viruses and other harmful
components and believe but not guarantee it virus-free prior
to leaving our computer system. However, you should satisfy
yourself that it is free from harmful components, as we do
not accept responsibility for any loss or damage it may
cause to your computer systems.
************************************************************
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list