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

Re: scoping inside a select statement

Subject: Re: scoping inside a select statement
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Wed, 12 Feb 2003 18:32:51 -0500
if inside select
Hey Simon,

At 05:45 PM 2/12/2003, you wrote:
Why does this DWIM:
 <xsl:variable name="foobar" select="@name"/>
 <xsl:value-of select="document('inst.xml')//*[boolean(name() = $foobar)]"/>

and this doesn't:
 <xsl:value-of select="document('inst.xml')//*[boolean(name() = @name)]"/>

... or perhaps I should say, how do I scope @name inside a select to refer to the @name attribute of the context node outside the select, instead of whatever it's referring to here (... an attribute named @name in the context node inside the select?)

There is an XSLT function, current(), that returns the current node (the node matched by the template or selected by a for-each), so when the context changes in a long XPath, you can still get to it.


<xsl:value-of select="document('inst.xml')//*[name() = current()/@name]"/>

(BTW notice that boolean() function isn't needed: "" already returns a Boolean and the fact that this is a predicate expression would coerce it to one even if it weren't.)

Another technique, sometimes preferable, is to bind your current node to a variable and refer to that.

Cheers,
Wendell

Also if you're wondering about the unnecessary boolean() I've decided to use it for syntactic safety to protect myself from numeric result s;-)

But when will the expression "name() = current()/@name" return a number? And even if it were ... since it's a predicate expression it'd be coerced into a Boolean anyway. :-)




======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================


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.