This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: A really easy (hopefully) question



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@lists.mulberrytech.com
[mailto:owner-xsl-list@lists.mulberrytech.com]On Behalf Of Chris Gow
Sent: Thursday, February 08, 2001 12:47 PM
To: XSL-List@lists.mulberrytech.com
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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]