Thomas,
Muenchian grouping gets complex and ugly (or: uglier ;-) when it goes
to multiple levels, because keys have document-wide scope. So in your
case, for example, to avoid the problem you describe, the second key
would have to be a "compound" key, as in
<xsl:key name="product" match="/csv_data_records/record"
use="concat(item[2], item[4])"/>
and called accordingly.
However, there may be other, nicer methods. See the approach Ken
Holman has tried to instill in our minds, variable-based grouping, as
described at
http://www.biglist.com/lists/xsl-list/archives/200401/msg00070.html
Basically the idea is to use variables to collect together all the
nodes to be grouped, and to select from those variables to collect
your subgroups. It goes to multiple levels much more nicely.
Note that construing Ken's code does require understanding that
generate-id(.)=generate-id($games[game=current()/game])
is the same as
generate-id(.)=generate-id($games[game=current()/game][1])
Another alternative that may be available to you: use XSLT 2.0.
Cheers,
Wendell
At 09:03 AM 2/28/2006, you wrote:
I have found various suggestions on this list, and links to more
explanatory pages describing the Muenchian technique to sort or group
xml data.
However, I am trying to do a kind of a double Muenchian, which is to
group xml data i two levels. but there must be something i am missing,
because it is not working as I expected.
The xml is the kind of standard data format:
<data>
<row>
<item name="1">data 1</item>
<item name="2">data 2</item>
<item name="3">data 3</item>
</row>
<row>
<item name="1">data 1</item>
<item name="2">data 2</item>
<item name="3">data 3</item>
</row>
</data>
My real xslt look like this:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0"
encoding="ISO-8859-1" indent="yes"/>
<!-- V A R I A B L E S -->
<xsl:key name="suplier" match="/csv_data_records/record"
use="item[2]"/>
<xsl:key name="product" match="/csv_data_records/record"
use="item[4]"/>
<xsl:template match="/">
<book>
<xsl:apply-templates/>
</book>
</xsl:template>
<xsl:template match="csv_data_records">
<xsl:for-each select="record[count(. |
key('suplier', item[2])[1])=1]">
<chapter>
<xsl:attribute
name="name"><xsl:value-of select="item[3]"/></xsl:attribute>
<xsl:attribute
name="value"><xsl:value-of select="item[2]"/></xsl:attribute>
<xsl:for-each
select="key('suplier', item[2])">
<product>
<xsl:attribute
name="group"><xsl:value-of
select="item[4]"/></xsl:attribute>
<xsl:for-each
select="key('product', item[4])">
<item>
<status>
<xsl:value-of select="item[1]"/>
</status>
<ean>
<xsl:value-of select="item[6]"/>
</ean>
<title>
<xsl:value-of select="item[7]"/>
</title>
</item>
</xsl:for-each>
</product>
</xsl:for-each>
</chapter>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
It seems that I am not getting the second grouping on the items right.
They are grouped all right, but they are repeated x times the node
item[4].
What have I missed out, or what am I doing wrong here.
/Thomas
======================================================================
Wendell Piez
mailto:wapiez(_at_)mulberrytech(_dot_)com
Mulberry Technologies, Inc. http://www.mulberrytech.com
17 West Jefferson Street Direct Phone: 301/315-9635
Suite 207 Phone: 301/315-9631
Rockville, MD 20850 Fax: 301/315-8285
----------------------------------------------------------------------
Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--