[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Variable creation and scoping

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

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

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
string.

If you went

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

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 
product
<xsl:value-of select="$foobar[4]/@foo * $foobar[4]/@bar"/>

David




 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.