Finding unique combinations from two nodesets

Discussion in 'XML' started by johkar, Apr 11, 2009.

  1. johkar

    johkar Guest

    I could use some help with coming up with all unique combinations of
    location@id and the coverageClass nodes

    So what I want to end up with is xml that would be:
    <combo>
    1 Class1
    1 Class2

    <?xml version="1.0" encoding="UTF-8"?>
    <company>
    <company_bs>
    <company_info>
    <location>
    <loc id="1"/>
    </location>
    <location>
    <loc id="2"/>
    </location>
    <location>
    <loc id="3"/>
    </location>
    <business>
    <businessType>
    <businessClass>
    <class>
    <coverageClass>Class1</coverageClass>
    </class>
    </businessClass>
    <businessClass>
    <class>
    <coverageClass>Class2</coverageClass>
    </class>
    </businessClass>
    <businessClass>
    <class>
    <coverageClass>Class3</coverageClass>
    </class>
    </businessClass>
    <businessClass>
    <class>
    <coverageClass>Class4</coverageClass>
    </class>
    </businessClass>
    <businessClass>
    <class>
    <coverageClass>Class5</coverageClass>
    </class>
    </businessClass>
    </businessType>
    </business>
    </company_info>
    </company_bs>
    </company>
    johkar, Apr 11, 2009
    #1
    1. Advertising

  2. johkar

    johkar Guest

    Sorry to top post, I accidently submitted. I need to end up with all
    the unique combinations.
    <company>
    <combo><loc>1</loc><class>Class1</class></combo>
    <combo><loc>1</loc><class>Class2</class></combo>
    <combo><loc>1</loc><class>Class3</class></combo>
    <combo><loc>1</loc><class>Class4</class></combo>
    <combo><loc>1</loc><class>Class5</class></combo>
    <combo><loc>2</loc><class>Class1</class></combo>
    <combo><loc>2</loc><class>Class2</class></combo>
    <combo><loc>2</loc><class>Class3</class></combo>
    <combo><loc>2</loc><class>Class4</class></combo>
    <combo><loc>2</loc><class>Class5</class></combo>
    <combo><loc>3</loc><class>Class1</class></combo>
    <combo><loc>3</loc><class>Class2</class></combo>
    <combo><loc>3</loc><class>Class3</class></combo>
    <combo><loc>3</loc><class>Class4</class></combo>
    <combo><loc>3</loc><class>Class5</class></combo>
    </company>

    On Apr 11, 5:54 pm, johkar <> wrote:
    > I could use some help with coming up with all unique combinations of
    > location@id and the coverageClass nodes
    >
    > So what I want to end up with is xml that would be:
    > <combo>
    > 1  Class1
    > 1  Class2
    >
    > <?xml version="1.0" encoding="UTF-8"?>
    > <company>
    >    <company_bs>
    >       <company_info>
    >          <location>
    >             <loc id="1"/>
    >          </location>
    >          <location>
    >             <loc id="2"/>
    >          </location>
    >          <location>
    >             <loc id="3"/>
    >          </location>
    >          <business>
    >             <businessType>
    >                 <businessClass>
    >                    <class>
    >                        <coverageClass>Class1</coverageClass>
    >                    </class>
    >                 </businessClass>
    >                 <businessClass>
    >                    <class>
    >                       <coverageClass>Class2</coverageClass>
    >                    </class>
    >                 </businessClass>
    >                 <businessClass>
    >                    <class>
    >                        <coverageClass>Class3</coverageClass>
    >                    </class>
    >                 </businessClass>
    >                 <businessClass>
    >                    <class>
    >                        <coverageClass>Class4</coverageClass>
    >                    </class>
    >                  </businessClass>
    >                  <businessClass>
    >                     <class>
    >                        <coverageClass>Class5</coverageClass>
    >                     </class>
    >                  </businessClass>
    >              </businessType>
    >          </business>
    >     </company_info>
    >  </company_bs>
    > </company>
    johkar, Apr 12, 2009
    #2
    1. Advertising

  3. johkar

    Peter Flynn Guest

    johkar wrote:
    > Sorry to top post, I accidently submitted. I need to end up with all
    > the unique combinations.
    > <company>
    > <combo><loc>1</loc><class>Class1</class></combo>
    > <combo><loc>1</loc><class>Class2</class></combo>
    > <combo><loc>1</loc><class>Class3</class></combo>
    > <combo><loc>1</loc><class>Class4</class></combo>
    > <combo><loc>1</loc><class>Class5</class></combo>
    > <combo><loc>2</loc><class>Class1</class></combo>
    > <combo><loc>2</loc><class>Class2</class></combo>
    > <combo><loc>2</loc><class>Class3</class></combo>
    > <combo><loc>2</loc><class>Class4</class></combo>
    > <combo><loc>2</loc><class>Class5</class></combo>
    > <combo><loc>3</loc><class>Class1</class></combo>
    > <combo><loc>3</loc><class>Class2</class></combo>
    > <combo><loc>3</loc><class>Class3</class></combo>
    > <combo><loc>3</loc><class>Class4</class></combo>
    > <combo><loc>3</loc><class>Class5</class></combo>
    > </company>


    If the document really is laid out like that, then use

    $ grep combo test.xml|sort|uniq
    <combo><loc>1</loc><class>Class1</class></combo>
    <combo><loc>1</loc><class>Class2</class></combo>
    <combo><loc>1</loc><class>Class3</class></combo>
    <combo><loc>1</loc><class>Class4</class></combo>
    <combo><loc>1</loc><class>Class5</class></combo>
    <combo><loc>2</loc><class>Class1</class></combo>
    <combo><loc>2</loc><class>Class2</class></combo>
    <combo><loc>2</loc><class>Class3</class></combo>
    <combo><loc>2</loc><class>Class4</class></combo>
    <combo><loc>2</loc><class>Class5</class></combo>
    <combo><loc>3</loc><class>Class1</class></combo>
    <combo><loc>3</loc><class>Class2</class></combo>
    <combo><loc>3</loc><class>Class3</class></combo>
    <combo><loc>3</loc><class>Class4</class></combo>
    <combo><loc>3</loc><class>Class5</class></combo>

    Otherwise you'll need XSLT or a similar tool to perform the extraction.

    ///Peter
    --
    XML FAQ: http://xml.silmaril.ie/
    Peter Flynn, Apr 12, 2009
    #3
    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. will

    xsl subsets of nodesets

    will, Jul 7, 2003, in forum: XML
    Replies:
    3
    Views:
    846
    Marrow
    Jul 8, 2003
  2. Hans-Michael Rupp
    Replies:
    2
    Views:
    1,912
    Marrow
    Jul 8, 2003
  3. breal
    Replies:
    14
    Views:
    928
    Steven D'Aprano
    Jan 17, 2008
  4. ToshiBoy
    Replies:
    6
    Views:
    831
    ToshiBoy
    Aug 12, 2008
  5. johkar
    Replies:
    6
    Views:
    915
    johkar
    Apr 19, 2009
Loading...

Share This Page