[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Re: [xsl] Using variables or parameters in tests
Subject: Re: [xsl] Using variables or parameters in tests From: David Carlisle <davidc@xxxxxxxxx> Date: Tue, 1 Mar 2005 23:33:19 GMT |
firstly, obligatory daily comment on this list:-) don't do this: <xsl:variable name="actualelectricity"> <xsl:value-of select="sum(/statement/item[$datetest and $electricitytest]/amount)"/> </xsl:variable> do this <xsl:variable name="actualelectricity" select="sum(/statement/item[$datetest and $electricitytest]/amount)"/> as it's less to type and loads more efficient as the variable then holds a number not a result tree fragment with a root node and a text node with string value the decimal representation of a number. However that doesn't really address your question... datetest = (date >= 20050228) variables hold values not expressions, so you while this <xsl:value-of select="sum(/statement/item[$datetest and $electricitytest]/amount)"/> is legal; $datetest would be a constant holding whatever value it is bound to, it wouldn't get a new value relative to each item node. in xslt1 if you want to store an expression that is going to be re-evaluated you need to put it in a named template. Then you could call that so long as you replaced sum(..) with a recursive template that iterated over the nodes calculating the sum and calling your named templates. in xslt2 draft you could define datetest as a function something like <xsl:function name="my:datetest" as="xs:boolean"> <xsl:param name="here"/> <xsl:sequence select="$here/date >= 20005028"/> </xsl:function> and similarly your other test then <xsl:value-of select="sum(/statement/item[my:datetest(.) and my:electricitytest(.)]/amount)"/> David ________________________________________________________________________ This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Using variables or parameters, Daniel O'Donnell | Thread | Re: [xsl] Using variables or parame, Wendell Piez |
[xsl] xhtml2fo.xsl not processing m, Random Blackburn | Date | [xsl] generating human-readable HTM, Kevin Rodgers |
Month |