Re: Can someone explain this snippet? Muenchian sorting.

Discussion in 'XML' started by Colin Mackenzie, Jul 3, 2003.

  1. see below

    "Jim Bancroft" <> wrote in message
    news:Q0YMa.35$...
    > 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
    >
    >
    >
    >
    >
    >
    >
    >
     
    Colin Mackenzie, Jul 3, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marrow
    Replies:
    2
    Views:
    1,247
    Marrow
    Jul 7, 2003
  2. Replies:
    1
    Views:
    641
    Joris Gillis
    Jun 6, 2006
  3. Replies:
    1
    Views:
    645
  4. Ajinkya

    explain the code snippet

    Ajinkya, May 11, 2007, in forum: C Programming
    Replies:
    8
    Views:
    443
    Chris Dollin
    May 14, 2007
  5. Replies:
    1
    Views:
    294
    Victor Bazarov
    Oct 22, 2007
Loading...

Share This Page