Subject: [xsl] Re[2]: Shorter, better, nicer XSLT From: Antonio Bueno <atnbueno@xxxxxxxxxx> Date: Sat, 16 Mar 2002 10:37:47 +0100 |
Hola, David. :) MD> I don't think I would recommend this, but you could replace all MD> the XSLT template complexity with XPATH complexity. [...] I send MD> it only for amusement. Well, thank you *very* much for sending it. Your solution is hard to read but the idea of moving complexity to XPath was new for me... And this morning I started to play around and came with a simpler (I think), not so hard to read (I hope) solution. And no, I don't know about its efficiency either. At the end of the message you have a stripped down version of another transformation (this one didn't search text, just select some "parrillas" and shows them), but the main idea is that to get parrilla[@fecha=$fecha] I use parrilla[contains(concat('*',@fecha),$fecha] The catch is that to use it for channels, I have to avoid channel IDs contained in other channel ID. I had a few of them (CP and CPA, FOX and FOXN, ...) in the full version but it's not a problem to change them because they are just arbitrary ones. Best, Antonio http://mundoplus.tv mailto:atnbueno@xxxxxxxxxxxx ----- parrillas0.xsl ------------------------------------------------- <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:param name="canal"/> <xsl:param name="fecha"/> <xsl:output doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" encoding="ISO-8859-1" indent="yes" method="xml"/> <xsl:template match="/"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"/> <title>mundoplus.tv - Parrillas de programación</title> </head> <body> <h1 class="titulo"> <xsl:text>Parrillas de programación</xsl:text> </h1> <form action="parrillas0.asp" method="get"> <div> <select name="canal"> <xsl:apply-templates select="programacion/canal"/> </select> <select name="fecha"> <xsl:apply-templates select="programacion/fecha"/> </select> <input class="submit" type="image" src="search.gif"/> </div> </form> <xsl:apply-templates select="programacion"/> <xsl:if test="($canal='')or($fecha='')"> <p> <xsl:text>Indique qué parrilla de programación desea ver.</xsl:text> </p> </xsl:if> </body> </html> </xsl:template> <xsl:template match="programacion"> <xsl:if test="($canal!='*')or($fecha!='*')"> <xsl:apply-templates select="parrilla[(contains(concat('*',@canal),$canal))and(contains(concat('*',@fecha),$fecha))]"/> </xsl:if> <xsl:if test="($canal='*')and($fecha='*')"> <p>Lo siento, pero has de escoger un canal o una fecha.</p> </xsl:if> </xsl:template> <xsl:template match="canal"> <option value="{@id}"> <xsl:if test="@id=$canal"> <xsl:attribute name="selected">selected</xsl:attribute> </xsl:if> <xsl:value-of select="."/> </option> </xsl:template> <xsl:template match="fecha"> <option value="{@id}"> <xsl:if test="@id=$fecha"> <xsl:attribute name="selected">selected</xsl:attribute> </xsl:if> <xsl:value-of select="."/> </option> </xsl:template> <xsl:template match="parrilla"> <div class="parrilla"> <br/> <b>'*<xsl:value-of select="@fecha"/>' does <xsl:if test="not(contains(concat('*',@fecha),$fecha))">not</xsl:if> contain '<xsl:value-of select="$fecha"/>'</b><br/> <br/> <b>'*<xsl:value-of select="@canal"/>' does <xsl:if test="not(contains(concat('*',@canal),$canal))">not</xsl:if> contain '<xsl:value-of select="$canal"/>'</b><br/> </div> </xsl:template> </xsl:transform> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Shorter, better, nicer XS, McNally, David | Thread | RE: [xsl] Variable in template atrr, Dion Houston |
[xsl] Enhanced SGML to XML conversi, G. Ken Holman | Date | RE: [xsl] Variable in template atrr, Michael Kay |
Month |