Re: [xsl] Variable creation and scoping

Subject: Re: [xsl] Variable creation and scoping
From: David Carlisle <davidc@xxxxxxxxx>
Date: Tue, 15 Apr 2003 20:52:33 +0100

<xsl:variable name="c1">
    <xsl;value-of select="document('external.xml')/a/b/c/@foo *

Note using xsl:variable with content rather than a select attribute
is relatively expensive. the above creates a result tree fragment
consisting of a root node containing a text node containing the value as a

If you went

<xsl:variable name="c1"
 select="document('external.xml')/a/b/c/@foo *

then the variable would contain a number, which is less to store and
quicker to use as a number later.

> Is there an easier/cleaner/better way to do this that will allow me to not
> edit the xsl when the xml file used to create the variables is altered?

Probably but the problem seems a little underspecified?
Do you need a variables at all? If there are an unknown number of
usable foo bar attribute pairs then it seems like you don't want
variables for each product, as that would limit you to a fixed number.

I'd go

<xsl:variable name="foobar"
select="document('external.xml')/a/b/c[string(@foo) and string(@bar)]"/>

now $foobar contains all the usable c nodes and to get the 4th 
<xsl:value-of select="$foobar[4]/@foo * $foobar[4]/@bar"/>


 XSL-List info and archive:

Current Thread