Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Re: Can someone explain this snippet? Muenchian sorting.

Reply
Thread Tools

Re: Can someone explain this snippet? Muenchian sorting.

 
 
Colin Mackenzie
Guest
Posts: n/a
 
      07-03-2003
see below

"Jim Bancroft" <(E-Mail Removed)> wrote in message
news:Q0YMa.35$(E-Mail Removed)...
> I've been reading up on the "Muenchian" sorting method on
> www.jenitennison.com, and saw this use of the count() function:
>
> <xsl:for-each select="contact[count(. | key('contacts-by-surname',
> surname)[1]) = 1]">
>
> What's happening is the code is trying to select the first node in a
> set, given a particular key. At least that's what I think.
>
> Anyway, the "count(. | key('contacts-by-surname', surname)[1]) = 1"

bit
> is throwing me for a loop, I can't figure out what's going on there. Are
> you trying to OR the current context node with the first value of the node
> set returned from the key() function? What happens when you do that?
>


the current context node . is being OR'd (a "set" operation) with the first
node returned from the key (as you say) to contain a node set with a
combination of both nodes
IF the current node IS the same node as that returned from the key then the
combined node set will only contain ONE node, therfore count(the combined
nodeset) would = 1
Therefore the count = 1 is True for that node, the [] predicate is true and
the node is processed by the logic within for-each (and so you get the first
name in the set presumably)

> Another way of doing the same thing seems to be as follows, (and

thanks
> to Marrow for helping me with a similar problem yesterday):
>
> "contact[generate-id() = generate-id(key('contacts-by-surname',
> surname)[1])]"
>
> I understand this a little more, it looks like you want the node whose
> id (conveniently created via "generate-id()") matches the first one

returned
> by the key. Please correct me if I misunderstood that or any other

portion
> of the code I posted. Thanks!


yes you are correct, but remeber the predicate [] portion is resolving to
true or false and can return true for multiple nodes (the first occurence of
a surname in a list)

>
> -Jim
>
>
>
>
>
>
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
I've done a Muenchian grouping, but how can I use it to generate summary info? lennyw@comcast.net XML 1 06-06-2006 08:59 PM
Muenchian problem mike@keeston-pembrokeshire.co.uk XML 1 05-10-2006 07:33 AM
Muenchian Grouping Method for Multiple Levels reclusive monkey XML 2 08-10-2005 02:04 PM
XSL grouping (Muenchian) Tristan Miller XML 2 01-31-2005 11:59 AM
Re: Can someone explain this snippet? Muenchian sorting. Marrow XML 2 07-07-2003 05:06 PM



Advertisments