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

Re: [XSLT 2.0] Creating a changeable globally scoped v

Subject: Re: [XSLT 2.0] Creating a changeable globally scoped variable?
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Mon, 22 Mar 2004 10:06:11 +0000
creating functions in xslt
Hi Roger,

> 2. Create a range variable with a sequence of values.  From reading the
> specs this seemed promising.  Here's an example of how this might work:
>
>    <xsl:template match="/">
>       <xsl:value-of select="for $i in (1 to 10) return (ex:print())"/>
>    </xsl:template>
>
>    <xsl:function ex:print">
>        <xsl:value-of select="$i"/>
>    </xsl:function>
>
> From reading the specs I got the impression that the range variable
> ($i) would have a scope over everything within "return (...)". In my
> example, within the return is a call to a function. I was thinking
> that the range variable's scope would extend to the ex:print
> function. Alas, it doesn't (unless there is a bug in SAXON).

The variable's scope is *lexically* within the return expression, so
you can use the variable reference $i within that expression, but you
can't use it elsewhere (such as the body of the function). The same is
true at the XSLT level: declaring a variable in one template does not
make it available in any other template, even those called from it.

If you just want to print the values 1 to 10 via a function, pass the
value of $i into the ex:print() function as a parameter:

<xsl:template match="/">
  <xsl:value-of select="for $i in (1 to 10) return (ex:print($i))"/>
</xsl:template>

<xsl:function name="ex:print">
  <xsl:param name="i" />
  <xsl:value-of select="$i"/>
</xsl:function>

But as others have said, you can't update a variable in XSLT, and
saying that you want to is usually a sign that you're approaching a
problem in an inappropriate way.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/

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.