Subject: Re: [xsl] XSL Sorting Question - Meunchian Method From: "Steve Muench" <Steve.Muench@xxxxxxxxxx> Date: Wed, 7 Nov 2001 22:40:11 +0100 |
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] 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] XSL Sorting Question - Meunch, Magick, Brian | Thread | Re: [xsl] XSL Sorting Question - Me, Jeni Tennison |
Re: [xsl] Re: lookup-table thoughts, David Carlisle | Date | Re: [xsl] Re: Re: Re: Re: Re: looku, David Carlisle |
Month |