This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: RE: xslt 2 grouping
- From: Dimitre Novatchev <dnovatchev at yahoo dot com>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Thu, 11 Jul 2002 09:28:32 -0700 (PDT)
- Subject: [xsl] Re: RE: xslt 2 grouping
- Reply-to: xsl-list at lists dot mulberrytech dot com
> > ><p>
> > ><el att='a'>x</el>
> > ><el att='b'>x</el>
> > ><el att='c'>x</el>
> > ><el att='d'>y</el>
> > ></p>
> > >I have about 1200 lines of this, so keys are out.
> >
> > Why discount keys?
>
> Because I have so many variants on (above) x, y.
> ditto on the att values, so I would have to define about 200 unique
> keys.
Hi Dave,
You need only 2 keys:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:key name="kVal" match="el" use="."/>
<xsl:key name="kValAttr" match="el"
use="concat(., '|', @att)"/>
<xsl:template match="/">
<xsl:for-each select="/*/el
[generate-id()
=
generate-id(key('kVal',.)[1])
]">
<el name="{.}">
<xsl:for-each select="/*/el
[
generate-id()
=
generate-id(key('kValAttr',
concat(current(),
'|',
@att)
)
[1]
)
]">
<xsl:value-of select="concat(@att, ' ')"/>
</xsl:for-each>
</el>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
When this transformation is applied on the following source xml:
<p>
<el att='a'>x</el>
<el att='b'>x</el>
<el att='c'>x</el>
<el att='d'>y</el>
<el att='m'>z</el>
<el att='m'>z</el>
<el att='0'>z</el>
<el att='d'>y</el>
<el att='a'>y</el>
<el att='f'>y</el>
<el att='k'>y</el>
<el att='k'>y</el>
</p>
the result is:
<el name="x">a b c </el>
<el name="y">d a f k </el>
<el name="z">m 0 </el>
=====
Cheers,
Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL
__________________________________________________
Do You Yahoo!?
Sign up for SBC Yahoo! Dial - First Month Free
http://sbc.yahoo.com
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list