XSLT: Selecting nodes by comparing data AFTER conversion

Discussion in 'XML' started by Ryan Adler, Jan 20, 2006.

  1. Ryan  Adler

    Ryan Adler Guest

    I have a terrible headache from this problem. Perhaps someone can
    help. My XML is formatted like this:

    <events>
    <event>
    <starts-at>123456<starts-at/>
    <event>
    ...
    <events/>

    The problem is, the starts-at field is actually a date-time, and I want
    to get all events that have the same _time_, but could have different
    dates. This means I first have to convert the data in that field, and
    then compare it. I already have a template to convert the data to the
    format I need, but how I can apply this template to all items, and then
    get the items that have the same output? And how can I do this within
    an XSLT page?
     
    Ryan Adler, Jan 20, 2006
    #1
    1. Advertising

  2. Ryan  Adler

    Soren Kuula Guest

    Ryan Adler wrote:
    > I have a terrible headache from this problem. Perhaps someone can
    > help. My XML is formatted like this:
    >
    > <events>
    > <event>
    > <starts-at>123456<starts-at/>
    > <event>
    > ...
    > <events/>
    >
    > The problem is, the starts-at field is actually a date-time, and I want
    > to get all events that have the same _time_, but could have different
    > dates. This means I first have to convert the data in that field, and
    > then compare it. I already have a template to convert the data to the
    > format I need, but how I can apply this template to all items, and then
    > get the items that have the same output? And how can I do this within
    > an XSLT page?
    >

    Seems to me like you have to make it a two-stager: First conversion,
    then grouping. Alternatively, in XSLT2.0 you can save the conversion
    result (of the whole doc) into a variable, and use that as input for 2nd
    sweep.

    Soren
     
    Soren Kuula, Jan 21, 2006
    #2
    1. Advertising

  3. Ryan  Adler

    Guest

    The tool-box <xml>cmp provides a grouping-tool xmltoxml.sh, which also
    can convert date-formats.

    You need a basic-control-file and a toxml-control-file for executing
    toxml.sh.

    basic-control-file: cmp126.xml

    <events>
    <event ident_att_nr="true">
    <starts_at
    ident_text="true"
    conv_text1_in="yyyy-MM-dd-HH:mm"
    conv_text1_out="HH:mm"
    conv_text1_class="de.sofika.test.ConvertDate"
    />
    </event>
    </events>

    toxml-control-file: toxml126

    <events>
    <starts_at ident_att_time="true"
    path_att_time="/events/event/starts_at">
    <event ident_att_nr="true" />
    </starts_at>
    </events>

    example-file: test126.xml

    <events>
    <event nr="1">
    <starts_at>2006-10-20-09:00</starts_at>
    </event>
    <event nr="2">
    <starts_at>2006-10-20-10:00</starts_at>
    </event>
    <event nr="3">
    <starts_at>2006-10-21-09:00</starts_at>
    </event>
    <event nr="4">
    <starts_at>2006-08-01-10:00</starts_at>
    </event>
    </events>


    Executing the grouping produce this result:

    $ xmltoxml.sh cmp126.xml toxml126.xml test126.xml
    <events>
    <starts_at time='09:00'>
    <event nr='1'>
    </event>
    <event nr='3'>
    </event>
    </starts_at>
    <starts_at time='10:00'>
    <event nr='2'>
    </event>
    <event nr='4'>
    </event>
    </starts_at>
    </events>

    <xml>cmp has also a comparing, sorting and merging-tool.
    See http://www.xmlcmp.com
     
    , Jan 31, 2006
    #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. Olivier Wulveryck
    Replies:
    1
    Views:
    694
    Andrew Thompson
    Sep 14, 2004
  2. Timo Nentwig

    selecting nodes between other nodes

    Timo Nentwig, Jun 16, 2004, in forum: XML
    Replies:
    1
    Views:
    428
    Patrick TJ McPhee
    Jun 17, 2004
  3. inquirydog

    comparing nodes in xslt

    inquirydog, Sep 29, 2004, in forum: XML
    Replies:
    5
    Views:
    587
    David Carlisle
    Oct 8, 2004
  4. Replies:
    1
    Views:
    604
    Soren Kuula
    Aug 24, 2006
  5. Andy Fish
    Replies:
    5
    Views:
    2,263
    Andy Fish
    Jul 31, 2007
Loading...

Share This Page