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]
Other format: [Raw text]

RE: generalized unique element


Hi Laura,

> <xsl:key match="*" use="name(.)" name="all-nodes"/>
> ..
> ...
> ....
> .....
> ......
> <xsl:if test="count(.| key('all-nodes', name(.))[1]) = 1">
> It works fine, i however do not understand what goes on in the above
line..

The xsl:key statement has set up an index of all nodes (match="*"), indexed
by their name (use="name(.)").
If you then supply the key() function with a value it returns the relevant
nodes as a nodeset. So,
key('all-nodes','foo') would return a nodeset of all the foo nodes in the
document. To extend this,
key('all-nodes', name(.)) returns all the nodes in the document with the
same name as your current node.
The addition of the [1] predicate filters this down to the first node in the
nodeset, which must be the
first in document order. Thus, key('all-nodes', name(.))[1] says "give me
the first element in document
order with the same name as the current element". The count function says
"count the number of nodes
which match the condition of being EITHER my current node (.) OR the first
node with the same name in
the document (obtained by the key() function)". So the only possible
condition in which a value of 1 could
be returned for this is if the current node IS the first node of that name
in the document.

Much the same with the generate-id() version: you are using key() to obtain
what you know is the first node
of that name in the document, and then comparing it with the current node to
see if they are one and the
same.

Took me a while to get my head round this, too!

Cheers,

Stuart


 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]