XPath help: Find element with most occurrences

Discussion in 'XML' started by STA, Jun 27, 2006.

  1. STA

    STA Guest

    Hi.

    Given this XML:
    <itemdata>
    <item>
    <itemid>10</itemid>
    <ctid>1</ctid>
    </item>
    <item>
    <itemid>11</itemid>
    <ctid>2</ctid>
    </item>
    <item>
    <itemid>12</itemid>
    <ctid>3</ctid>
    </item>
    <item>
    <itemid>13</itemid>
    <ctid>3</ctid>
    </item>
    <item>
    <itemid>14</itemid>
    <ctid>3</ctid>
    </item>
    <item>
    <itemid>15</itemid>
    <ctid>4</ctid>
    </item>
    <item>
    <itemid>16</itemid>
    <ctid>4</ctid>
    </item>
    </itemdata>

    How can I find the ctid that occurs the most times? In this sample, I'm
    looking for a result of "3", because there are 3 items where ctid=3,
    and the next closest (4) only has 2 occurrences.

    Thanks in advance for any help.
    STA
    STA, Jun 27, 2006
    #1
    1. Advertising

  2. STA wrote:
    > How can I find the ctid that occurs the most times?


    Just a SWAG, but: I'd suggest approaching this as a combination of a
    grouping problem (find the items with the same ctid) and a sorting
    problem (pick the longest group(s)).



    --
    () ASCII Ribbon Campaign | Joe Kesselman
    /\ Stamp out HTML e-mail! | System architexture and kinetic poetry
    Joe Kesselman, Jun 27, 2006
    #2
    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. H.MuthuKumaraRajan
    Replies:
    3
    Views:
    424
    H.MuthuKumaraRajan
    Feb 4, 2004
  2. Pete
    Replies:
    1
    Views:
    878
    Martin Honnen
    Nov 27, 2004
  3. Ian Wilson
    Replies:
    2
    Views:
    543
    Ian Wilson
    Jul 26, 2007
  4. xkenneth
    Replies:
    8
    Views:
    329
    Bruno Desthuilliers
    Feb 6, 2008
  5. MSUTech
    Replies:
    2
    Views:
    114
    Phill. W
    Jun 8, 2005
Loading...

Share This Page