RE: generalized unique element
Hi Laura, > <xsl:key match="*" use="name(.)" name="all-nodes"/> > .. > ... > .... > ..... > ...... > <xsl:if test="count(.| key('all-nodes', name(.))) = 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  predicate filters this down to the first node in the nodeset, which must be the first in document order. Thus, key('all-nodes', name(.)) 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
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format