xsl-list
[Top] [All Lists]

Re: Getting desired node on template match

2002-09-11 08:09:55

and It is working but I did not understand 
exactly what it is doing

This is Steve Meunch's devious trick. 

To see how it works it helps to lie down in a darkened rule and repeat
the secret XSLT chant until you are in the correct frame of mind. Then
just look at the code again and it all becomes clear.

Basically the problem is that you have a node "." and a set of nodes
returned by the key() function. What you want to know is if the node you
have is teh first element in the set. so..
key('contacts-by-surname', surname)[1]
is the first element (in document order) in the set.
and you want to know if this is the same node as .
you can't do
. = key('contacts-by-surname', surname)[1]
because that will test the string values of the nodes, it does not
test whether the nodes are the same. (So for example all empty elements
would be equal if tested with = as they all have string value "")

However

the set

(. | key('contacts-by-surname', surname)[1])

is the union of the set set consisting of . and the set consisting of
the first element returned by key(). Either this union has 1 element
or two. If it has two it means the key() function has returned a node
other than the current one.

David

_____________________________________________________________________
This message has been checked for all known viruses by Star Internet
delivered through the MessageLabs Virus Scanning Service. For further
information visit http://www.star.net.uk/stats.asp or alternatively call
Star Internet for details on the Virus Scanning Service.

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list