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

RE: How to: Reference to the current Nodeset while pr

Subject: RE: How to: Reference to the current Nodeset while processing through another one
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Wed, 29 Sep 2004 10:16:20 +0100
xsl variable current
My immediate answer to the question in your subject line is "use variables".

Now I see:

> I want to get all other "Value" items, having the same 
> id. I want to
> get them without using a referenc variable.

and my immediate reaction is: why? It's like saying you want to eat
spaghetti, and you want to do it without using a fork.

> 
> I tried:
> <xsl:for-each select="//Value[@id = Value/@id]">
> 	<!-- Do something -->
> </xsl:for-each>
> 
> But this returned all Values having a attribut "id".

I'm surprised this would return anything. It asks for all Value elements
that have an @id attribute and that have a child Value element with the same
value of @id.
> 
> If I declare a variable with the value of "id"
> <xsl:variable name="v_id">
> 	<xsl:value-of select="@id"/>
> </xsl:variable>

It's better to write this as

<xsl:variable name="v_id" select="@id"/>

but in this case either will work.

> and process though the other nodes by using the variable it works:
> <xsl:for-each select="//Value[@id = $v_id]">
> 	<!-- Do something -->
> </xsl:for-each>
> 
> In this case I get all "Value" nodes having a "id" of "123".
> But how can I do this without using a variable? 

If you really hate variables that much, you can often get by with current(),
which is in effect a built-in variable set to the node that was the current
node at the outermost level of the XPath expression. So you can write

<xsl:for-each select="//Value[@id = current()/@id]">

Incidentally, this would be much faster with keys.

Michael Kay
http://www.saxonica.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.