[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
RE: [xsl] A really easy (hopefully) question
Subject: RE: [xsl] A really easy (hopefully) question From: "Evan Lenz" <elenz@xxxxxxxxxxx> Date: Thu, 8 Feb 2001 13:30:28 -0800 |
The "current node" and "current node list" are XSLT concepts, not XPath concepts. What would you expect current() to return in another non-XSLT implementation of XPath? Steps in an XPath expression (separated by "/") are evaluated within a particular context, which includes, among other things, a "context node". The context node changes for each step of the XPath expression. To call current() would be to access a node outside the scope of XPath's evaluation context. As it turns out, current() returns the node that *was* the context node at the first step of the XPath expression. This node has special status in XSLT, because it is part of the current node list being processed, either by <xsl:for-each> or <xsl:apply-templates/>. Outside the context of XSLT, this special status might seem fairly arbitrary. What you want is a mechanism for accessing a node outside the scope of the context node. Well, you're in luck. Also part of XPath's evaluation context is a set of variable bindings. Your XPath implementation need only set up a way to declare variables, and then you can reference them in your XPath expressions. This is much more flexible than the current() function which returns a node that only makes sense in the context of XSLT. Technically, you don't even need the current() function in XSLT, because you can always declare a variable bound to the current node and then reference it in the XPath expression. For example, <xsl:for-each select="car"> <xsl:copy-of select="part[@color=current()/@color]"/> </xsl:for-each> could be re-written as follows: <xsl:for-each select="car"> <xsl:variable name="color" select="@color"/> <xsl:copy-of select="part[@color=$color]"/> </xsl:for-each> Hope this helps! Evan Lenz XYZFind Corp. -----Original Message----- From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Chris Gow Sent: Thursday, February 08, 2001 12:47 PM To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx Subject: [xsl] A really easy (hopefully) question Hi: I have a question that I've been wanting to ask for a while and thought today would be a pretty good day (for me anyways) to ask. How come the current() function is part of the XSLT spec ant not XPath? It seems from what I've seen of it/how its been used, it would be more appropriate to be in XPath instead of being only available as XSLT. For example, in the case XPath only implementations how would a user do a comparison of two separate branches without resorting to some sort of extension function (which XPath doesn't deal with). Just curious. Thanks Chris XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] A really easy (hopefully) que, Chris Gow | Thread | RE: [xsl] A really easy (hopefully), Michael Kay |
[xsl] Final Announcement: Ottawa-ar, G. Ken Holman | Date | Re: [xsl] XInclude in Cocoon, Uche Ogbuji |
Month |