Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 7th, 2008, 01:20 PM
Registered User
 
Join Date: Apr 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default help with Muenchian method grouping...

Here's my input xml...

<Collection>
<Content>
<Title>Portland</Title>
<root>
  <Topic>Cities</Topic>
</root>
</Content>
<Content>
<Title>Tinyville</Title>
<root>
  <Topic>Towns</Topic>
</root>
</Content>
...
</Collection>


Here's my desired output...
Cities
Albany
Portland
...etc...
Towns
Tinyville
Smithtown
...etc...


And here's my attempt thus far...
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>
<xsl:key name="content-by-topic" match="Content" use="Topic"/>
<xsl:template match="/">
<xsl:if test="string-length(Collection/Content) > 0">
    <h2>Websites</h2>
</xsl:if>
<xsl:template match="Collection">
    <xsl:for-each select="Content[count(. | key('content-by-topic', root/Topic)[1]) = 1]">
        <xsl:sort select="root/Topic" />
        <xsl:value-of select="root/Topic" /><br />
        <xsl:for-each select="key('content-by-topic', root/Topic)">
            <xsl:sort select="Title" />
            <xsl:value-of select="Title" /><br />
        </xsl:for-each>
    </xsl:for-each>
</xsl:template>
</xsl:template>
</xsl:stylesheet>


Unfortunately, as this is my first attempt with the Meunchian method, I've broken something... It's not working quite right for me.

Any ideas?

Thanks!!



 
Old April 7th, 2008, 04:53 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

<xsl:key name="content-by-topic" match="Content" use="Topic"/>

Try use="root/Topic"

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
help with Muenchian method grouping and html table mickhughes XSLT 3 May 1st, 2008 06:24 AM
Muenchian grouping amhicraig XSLT 1 December 5th, 2007 06:43 PM
Muenchian Grouping Chamkaur XSLT 1 June 21st, 2006 10:51 AM
Advanced Grouping Using the Muenchian Method Bodiam XSLT 0 August 8th, 2005 11:33 AM
Grouping XML by Muenchian Method - Urgent :-( xrow XSLT 5 September 28th, 2004 04:07 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.