[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Anyone can explain me this syntax?

Subject: RE: Anyone can explain me this syntax?
From: "Jaime Stuardo" <jstuardo@xxxxxxxxxxx>
Date: Tue, 13 Jan 2004 15:01:07 -0400
stuardo
Thanks Wendell for your complete explanation. While reading your help, I tested another alternative:

ROW[. = key('relacion_x_cobertura', REL_ID)[1]]

and it worked too. The actual XML structure has 35 ROW's, the first 7 ROW's has REL_ID = 1, the following 7 ROW's has REL_ID = 2, and so on (this was a particular case where exist 7 ROW's for each REL_ID).

I think that the new way above worked because all of the ROW's are different (besides REL_ID, the ROW has other fields), and since key('relacion_x_cobertura', REL_ID)[1] returns only 1 node where the key is equal to REL_ID, by comparing . with the key value, returns only 1 ROW, the ROW that allows me to group by REL_ID=1, REL_ID=2, until REL_ID = 5.

I think that case is equivalent to generate-id method since all ROW's has at least 1 field different, making the whole ROW different. Is that true?

Jaime

-----Mensaje original-----
De: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]En nombre de Wendell Piez
Enviado el: Martes, 13 de Enero de 2004 13:28
Para: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Asunto: 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...
>
> >From Muenchian method of grouping, I always use something like this:
>
>ROW[count(. | key('relacion_x_cobertura', REL_ID)[1]) = 1]
>
>That always works, but I want to understand he reason of that syntax, so 
>that if I don't have the possibility of doing copy & paste from other 
>code, I could be able to write that expression by myself.
>
>I know that instruction only returns the different elements contained in 
>ROW. That difference is determined by REL_ID value.
>
>But the actual questions are:
>
>- Why the . (dot) is used? why if I omit it, it doesn't work (it returns 
>all elements)?
>- What's the meaning of the | (pipe)?
>- What's the meaning of [1]? I have always used things like 
>[FIELD_NAME=some_value]. I understand that perfectly, but what about 
>placing only that number in the brackets? I tried by using [2] and it 
>worked too... or, perhaps I was lucky?


======================================================================
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



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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.