[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: XSL Sorting Question - Meunchian Method

Subject: Re: XSL Sorting Question - Meunchian Method
From: "Steve Muench" <Steve.Muench@xxxxxxxxxx>
Date: Wed, 7 Nov 2001 22:40:11 +0100
meunchian method xsl
Something like this should do the trick:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
  <xsl:key name="proj" match="project_name" use="."/>
  <xsl:key name="cust4proj" match="PROROW" use="project_name"/>
  <xsl:template match="PROJECTS">
        <xsl:apply-templates select="PROROW/project_name[generate-id(.) =
                                            generate-id(key('proj', .)[1])]"/>
  </xsl:template>
  <xsl:template match="project_name">
    <b><xsl:value-of select="."/></b>
    <ul>
      <xsl:for-each select="key('cust4proj',.)">
        <li>
          <a href="projects_results.xml?project={../id}">
             <xsl:value-of select="name" />
          </a>
        </li>
      </xsl:for-each>
    </ul>
  </xsl:template>
</xsl:stylesheet>


_____________________________________________________________________
Steve Muench - Developer, Product Manager, XML Evangelist, Author
"Building Oracle XML Applications" - www.oreilly.com/catalog/orxmlapp
  
----- Original Message ----- 
From: "Magick, Brian" <Brian.Magick@xxxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Wednesday, November 07, 2001 10:15 PM
Subject:  XSL Sorting Question - Meunchian Method


| I've been reading Jenni Tennisons's web site and looking at the grouping
| examples to help solve a problem.  One example uses the following XML
| and XSL to output something similar to this:
| 
| Customer 1 
| * Project 1 
| * Project 2 
| Customer 2 
| * Project 1 
| 
| Based on this XSL:
| 
| <?xml version="1.0" encoding="UTF-8"?>
| <xsl:stylesheet version="1.0"
| xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|       <xsl:output method="xml" version="1.0" encoding="UTF-8"
| indent="yes"/>
|       <xsl:key name="rows" match="PROROW" use="name"/>
|       <xsl:template match="PROJECTS">
|             <xsl:apply-templates select="PROROW[generate-id(.) =
| generate-id(key('rows', name)[1])]"/>
|       </xsl:template>
|       <xsl:template match="PROROW">
|             <b>
|                   <xsl:value-of select="name"/>
|             </b>
|             <ul>
|     <xsl:for-each select="key('rows', name)/project_name">
|       <li>
|         <a href="projects_results.xml?project={../id}">
|           <xsl:value-of select="." />
|         </a>
|       </li>
|     </xsl:for-each>
|             </ul>
|       </xsl:template>
| </xsl:stylesheet>
| 
| and this XML: (which differs slightly from the XML on her web page)
| 
| <?xml version="1.0" encoding="UTF-8"?>
| <PROJECTS>
|       <PROROW>
|             <id>1</id>
|             <name>Customer 1</name>
|             <project_name>Project 1</project_name>
|             <project_name>Project 2</project_name>
|       </PROROW>
|       <PROROW>
|             <id>2</id>
|             <name>Customer 2</name>
|             <project_name>Project 1</project_name>
|       </PROROW>
| </PROJECTS>
|  
| I would like to mix this up a bit and sort by project_name outputting a
| list of customers per project like this:
| 
| 
| Project 1
|      *Customer 1
|      *Customer 2
| Project 2
|      *Customer 1
|  
| I think the change is very subtle and minor to get here but so far I've
| been unsuccessful.  Any pointers?
|  
| Brian
| 
| 
|  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
| 
| 


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.