Subject: RE: [xsl] compare out of context? From: "Thomas Vanparys" <thomas.vanparys@xxxxxxxxxx> Date: Tue, 2 Nov 2004 23:43:13 +0100 |
Hi again, I found an answer: passing parameters in the template calls all the way down to the point I need them. I'm pretty sure my code looks aweful at this point but it works. If anyone has any tips on how I could optimise the routine I'm all ears. -Thomas -------[BEGIN SOURCE XSL]-------- <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" doctype-public="-//W3C//DTD HTML 4.0 Transitional//EN"/> <xsl:key name="artists" match="mp3" use="artist/displayname" /> <xsl:key name="albums" match="mp3" use="album/displayname" /> <xsl:key name="artists_albums" match="mp3" use="concat(artist/displayname, ' ', album/displayname)" /> <xsl:template match="mp3list"> <html> <head> <style> .header { font-size: larger; font-weight: bold; cursor: hand; cursor:pointer; background-color:#cccccc; font-family: Verdana; } .details { background-color:#eeeeee; font-family: Verdana; } .fadeout { color:#F0C2BB; } </style> </head> <body> <xsl:for-each select="mp3[count(. | key('artists', artist/displayname)[1]) = 1]"> <xsl:sort select="artist/displayname" /> <xsl:variable name="top_artist" select="artist/displayname" /> <h1><xsl:value-of select="$top_artist" /></h1> <xsl:variable name="album_items" select="key('artists', artist/displayname)" /> <xsl:for-each select="$album_items[generate-id() = generate-id(key('artists_albums', concat(artist/displayname, ' ', album/displayname))[1])]"> <xsl:sort select="album/displayname" /> <xsl:call-template name="album_title"/> <xsl:call-template name="album_content"> <xsl:with-param name="passed_param"> <xsl:value-of select="$top_artist"/> </xsl:with-param> </xsl:call-template> </xsl:for-each> </xsl:for-each> <xsl:call-template name="page_footer"/> </body> </html> </xsl:template> <xsl:template name="album_title"> <xsl:element name="h3"> <xsl:attribute name="id"><xsl:value-of select="concat('h',generate-id(.))" /></xsl:attribute> <xsl:attribute name="class">header</xsl:attribute> <xsl:value-of select="album/displayname" /> </xsl:element> </xsl:template> <xsl:template name="album_content"> <xsl:param name="passed_param"/> <xsl:element name="div"> <xsl:attribute name="id"><xsl:value-of select="concat('d',generate-id(.))" /></xsl:attribute> <xsl:attribute name="class">details</xsl:attribute> <table> <tr> <th>No.</th> <th>Title</th> <th>Length</th> <th>bitrate</th> <th>vbr</th> </tr> <xsl:for-each select="key('albums', album/displayname)"> <xsl:sort select="trackindex" data-type="number"/> <tr> <xsl:call-template name="highlighter"> <xsl:with-param name="passed_param"> <xsl:value-of select="$passed_param"/> </xsl:with-param> </xsl:call-template> <td><xsl:number format="01 " value="trackindex"/></td> <td><xsl:value-of select="title"/></td> <td><xsl:value-of select="length"/></td> <td><xsl:value-of select="bitrate"/></td> <td><xsl:value-of select="vbr"/></td> </tr> </xsl:for-each> </table> </xsl:element> </xsl:template> <xsl:template name="highlighter"> <xsl:param name="passed_param" select="'Default Data'"/> <xsl:if test="$passed_param != artist/displayname"> <xsl:attribute name="class">fadeout</xsl:attribute> </xsl:if> </xsl:template> <xsl:template name="page_footer"> <hr/> </xsl:template> </xsl:stylesheet> -------[END SOURCE XSL]--------
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] compare out of context?, Thomas Vanparys | Thread | Re: [xsl] compare out of context?, Geert Josten |
Re: [xsl] filtering, Geert Josten | Date | RE: [xsl] inserting HTML comments, Pieter Reint Siegers |
Month |