This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Meunchian Method - Grouping with attributes
- From: "G. Ken Holman" <gkholman at CraneSoftwrights dot com>
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Sat, 26 Jan 2002 10:17:59 -0500
- Subject: Re: [xsl] Meunchian Method - Grouping with attributes
- Reply-to: xsl-list at lists dot mulberrytech dot com
At 2002-01-25 15:56 -0600, Magick, Brian wrote:
>I'm having a tough time grouping on an attribute where I need to get
>only unique values of the domain attribute for each unique technology.
I find double-level grouping is more easily implemented using variables
than using keys.
I hope the example below helps.
.................... Ken
t:\ftemp>type brian.xml
<?xml version="1.0" encoding="utf-8"?>
<document>
<products>
<product>Product1
<technology domain="xyz">tech1</technology>
<technology domain="abc">tech1</technology>
<technology domain="xyz">tech2</technology>
<technology domain="xxx">tech2</technology>
<technology domain="xyz">tech3</technology>
</product>
<product>Product2
<technology domain="xyz">tech1</technology>
<technology domain="abc">tech1</technology>
<technology domain="zzz">tech2</technology>
<technology domain="xxx">tech2</technology>
<technology domain="aaa">tech3</technology>
</product>
</products>
</document>
t:\ftemp>type brian.xsl
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output omit-xml-declaration="yes"/>
<xsl:template match="/">
<xsl:variable name="technologies" select="//technology"/>
<xsl:for-each select="$technologies">
<xsl:if test="generate-id(.)=
generate-id($technologies[.=current()])">
<xsl:value-of select="."/><xsl:text>
</xsl:text>
<xsl:variable name="domains"
select="$technologies[.=current()]/@domain"/>
<xsl:for-each select="$domains">
<xsl:if test="generate-id(.)=
generate-id($domains[.=current()])">
<xsl:text> domain = </xsl:text>
<xsl:value-of select="."/><xsl:text>
</xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
t:\ftemp>xt brian.xml brian.xsl
tech1
domain = xyz
domain = abc
tech2
domain = xyz
domain = xxx
domain = zzz
tech3
domain = xyz
domain = aaa
t:\ftemp>
--
Upcoming: 3-days XSLT/XPath and/or 2-days XSLFO - Feb 18-22, 2002
G. Ken Holman mailto:gkholman@CraneSoftwrights.com
Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (Fax:-0995)
ISBN 0-13-065196-6 Definitive XSLT & XPath
ISBN 1-894049-08-X Practical Transformation Using XSLT and XPath
ISBN 1-894049-07-1 Practical Formatting Using XSLFO
XSL/XML/DSSSL/SGML/OmniMark services, books(electronic, printed),
articles, training(instructor-live,Internet-live,web/CD,licensed)
Next public training: 02-02-11,12,14,15,18,21,03-04,05,06,08,11,
- 04-08,09,10,12,05-14,15,06-04,07
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list