Subject: [xsl] Grouping headers revisted From: Jeroen Janssen <jeroen@xxxxxxxx> Date: Fri, 31 Aug 2001 11:49:10 +0200 |
Hi, First of all, thanks to everyone who answered my last question (about grouping headers), you where all very helpful and I've learned from your responses. Unfortunately my problem has turned out to be a bit more complex than I previously thought. I've tried to work out a solution myself, but it's a bit too complicated for my (limited) knowledge of xsl. I have two parameters in my xsl 'discipline' and 'subdiscipline' and I have the following xml: <country name="The Netherlands"> <institutions> <institution> <name>School of pretentious art</name> <city>Amsterdam</city> <disciplines> <discipline name="music"> <subdiscipline name="rock"/> <subdiscipline name="free jazz"/> </discipline> </disciplines> </institution> <institution> <name>Dendermalsen School of things</name> <city>Dendermalsen</city> <disciplines> <discipline name="theatre" shortname="theatre"> <subdiscipline name="mime"/> </discipline> <discipline name="music"> <subdiscipline name="rock"/> <subdiscipline name="free jazz"/> </discipline> </disciplines> </institution> <institution> <name>School of music</name> <city>Amsterdam</city> <disciplines> <discipline name="music"> <subdiscipline name="rock"/> <subdiscipline name="free jazz"/> </discipline> </disciplines> </institution> <institution> <name>School van artistieke dingen</name> <city>Amsterdam</city> <disciplines> <discipline name="music"> <subdiscipline name="rock"/> </discipline> <discipline name="theatre"> <subdiscipline name="mime"/> <subdiscipline name="drama"/> </discipline> </disciplines> </institution> </institutions> </country> I want to generate a list based on the parameters, so if I have param 'discipline' = music and param 'subsdiscipline' = free jazz I want to show only the institutions that offer not only music, but only free jazz music, so in this particular case 3 institutions will be shown. These parameters are optional by the way, so one could also select just 'music'. The thing that makes it more complicated is that I also want to group the resulting institutions by city, so the previous example would result in: Amsterdam School of pretentious art School of music Dendermalsen Dendermalsen School of things Sorry for the long post, but this problem is making my head hurt :-) This is the xsl I have so far, it's probably not very useful as it doesn't really do what it's supposed to do but I'll include it anyway: <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:param name="discipline">music</xsl:param> <xsl:param name="subdiscipline">free jazz</xsl:param> <xsl:key name="disciplines" match="institution" use="disciplines/discipline/@name"/> <xsl:key name="subdisciplines" match="institution" use="disciplines/discipline/subdiscipline/@name"/> <xsl:key name="institutions" match="institution" use="city"/> <xsl:template match="/"> <html> <head> <title></title> </head> <body> <xsl:apply-templates/> </body> </html> </xsl:template> <xsl:template match="information"> </xsl:template> <xsl:template match="institutions"> <xsl:apply-templates select="key('disciplines' , $discipline)"> <xsl:sort select="city" order="ascending"/> </xsl:apply-templates> </xsl:template> <xsl:template match="institution"> <br/> <xsl:if test="generate-id() = generate-id(key('institutions',city)[1])"> <b><xsl:value-of select="city"/></b><br/> </xsl:if> <xsl:apply-templates select="name"/> <xsl:apply-templates select="disciplines"/> </xsl:template> <xsl:template match="institution/name"> <font color="red"><xsl:apply-templates/></font><br/> </xsl:template> <xsl:template match="disciplines"> <i>(<xsl:apply-templates/>)</i><br/> </xsl:template> <xsl:template match="discipline"> <xsl:value-of select="@name"/>, </xsl:template> </xsl:stylesheet> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Parameterized attribute, Jarno . Elovirta | Thread | RE: [xsl] Parameterized attribute, Haque, Suraiya |
Re: [xsl] how to test the existence, David Carlisle | Date | [xsl] Invoking a servlet with docum, Crook, Charles |
Month |