|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Anyone can explain me this syntax?
Jaime,
To add to others' responses ... the point of the expression is to select a single node that can serve as a representative or "flagbearer" node for a group of nodes. If we know exactly which group we want, this is not hard -- for example, in your case if we want the group of nodes matching the key 'relacion_x_cobertura' with REL_ID value of 'x', we'd say key('relacion_x_cobertura', 'x')[1] -- that is, the first node (the [1] predicate) in document order of the set returned by the key function with value 'x' as the key. But what if we don't want a particular unique flagbearer, but one flagbearer each for *all* the key values in our document? The only way to do this in XSLT 1.0 is to collect all the candidates and test each one to see if it's the designated flagbearer for its set (throwing away the ones that aren't). This means we have to compare each node in turn to key('relacion_x_cobertura', 'x')[1], and see if it's the same node. (Fortunately this test can be performed in the predicate of a path expression that would otherwise select all the candidates.) Since XSLT 1.0 does not have a real node-identity test, we can't do this by simply comparing them. Accordingly we have a workaround test, which takes the form of count($node | $nodeset[1]) = 1 this will be the case if $node and $nodeset[1] are the same, but not if they are two different nodes. (This is why your test worked when you said [2] instead of [1], since [2] picks a single node just as [1] does. But yes, you were lucky: if any of your sets didn't have a second member, returning an empty node set from $nodeset[2], you'd be sunk.) Another way to perform this same test is to say generate-id($node)=generate-id($nodeset[1]) which is why we also see the Muenchian technique used in the form ROW[generate-id(.) = generate-id(key('relacion_x_cobertura', REL_ID)[1])] which can be abbreviated as
ROW[generate-id() = generate-id(key('relacion_x_cobertura', REL_ID))]since the generated ID (a string) of a set of nodes will be the generated ID of the first node in the set. The essence of the Muenchian grouping technique could be summarized as "collect the nodes to be grouped and de-duplicate by the grouping criterion to select a set of unique flagbearers; iterate over that set and with each iteration take the flagbearer and all the nodes in its group". I hope this helps-- Wendell At 10:58 AM 1/13/2004, you wrote: Hi all... ====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ====================================================================== 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
|

Cart








