xsl-list
[Top] [All Lists]

Re: Using variables or parameters in tests

2005-03-01 16:33:19

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 &gt;= 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
________________________________________________________________________

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>