[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
RE: [xsl] generalized unique element
Subject: RE: [xsl] generalized unique element From: Stuart Brown <sbrown@xxxxxxxxxxxxx> Date: Wed, 11 Sep 2002 15:54:48 +0100 |
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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] generalized unique elemen, Laura Jenkins | Thread | Re: Re: [xsl] generalized unique el, scruss |
RE: [xsl] FW: XML/XSL output, Girish.Savadatti | Date | Re: Re: [xsl] generalized unique el, scruss |
Month |