xsl-list
[Top] [All Lists]

RE: Setting values for variable

2004-09-10 10:29:16
That is, too, am example of a begginers wrong way of doing things. My mistake.

Yuo?re right, ofcourse, but this is one i allways forget... :(


Quoting Michael Kay <mhk(_at_)mhk(_dot_)me(_dot_)uk>:

But just to ilustrate how vars should be used,

            <xsl:variable name="t1">
                    <xsl:value-of
select="sum(/Trade/Record[Payment]/Payment)" />
            </xsl:variable>


Don't use this construct unless you have a very good reason. It's much
better to write:

<xsl:variable name="t1"
              select="sum(/Trade/Record[Payment]/Payment)" />

Why?

Firstly, it's shorter and more readable.

More importantly, the resulting value is a number, not a result tree
fragment. A number is a much simpler object than a result tree fragment, so
it's cheaper to create and cheaper to access. There are also some contexts,
for example in the predicate P[$t1], where it's important for correct
operation that the value should be a number.

Michael Kay


--+------------------------------------------------------------------
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>
--+--









O SAPO já está livre de vírus com a Panda Software, fique você também!
Clique em: http://antivirus.sapo.pt


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