Subject: Re: [xsl] Finding another element with the same name as the current node From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx> Date: Fri, 2 Feb 2001 07:11:55 +0000 |
Hi Jo, > Thankyou so much! This explanation is just wonderful! One thing I am > wondering, with the key option: > > <xsl:apply-templates select="key('branch1-elements', name())" /> > > Is why I don't need name() = name(current() like I do for the other > options? I wondered if you'd wonder that ;) You *can* use name(current()) if you want, it's just that here that has the same effect as just name(). When you use name() without any arguments, it gives you the name (technically the 'expanded name') of the *context node*. The context node is the node that's being looked at *within the XPath* when the expression is being evaluated. The current node, on the other hand, is the node that's being looked at *within the XSLT*. For example, take something like: //branch1/*[name() = name(current())] At the very start, as with all expressions, the context node is set to the current node, so if we're in a template for a branch2 element, then that branch2 element is the context node at the start of the expression. The first part of the path (/) changes the context node to the root node, and as you go through each step the context node changes, to the descendants of the root node, to their branch1 element children, and to their element children. Within the predicate, the context node is one of those children of the branch1 element. So, within the predicate, name() gives the name of one of those elements and you have to use name(current()) to get the name of the current node. On the other hand, in the expression: key('branch1-elements', name()) there's only one step (if you can call it a step): the call to the key. The context node doesn't change within the function call - it's still the current node. So name() gives the name of the current node. Of course, after the call to the key, the context node *is* changed, so if you had a predicate on the key: key('branch1-elements', name())[1] then within the predicate, the context node would be one of the nodes returned by the key. I hope that makes sense, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Finding another element w, Jo Bourne | Thread | RE: [xsl] Finding another element w, Michael Kay |
RE: [xsl] Selecting all the childre, Clapham, Paul | Date | Re[2]: [xsl] Javascript Function wi, viewga |
Month |