1 2 Previous Next 16 Replies Latest reply: Jun 16, 2014 6:52 AM by 2687447 RSS

    How to compare with previous value?

    2687447

      I have a condition like, I have to compare my current value with previous record i.e. consider a table

      DateTypeStartTimeEndTime
      5/7/2014Work8:00AM4:00PM
      5/7/2014Lunch12:00PM12:30PM

      Now I want to compare 'StartTime(12:00PM)' for 'Type=Lunch' with previous 'EndTime(4:00PM)' for 'Type=Work'

      How can I do this? Is there any 'Preceding' function or somthing.

      Please help me on this if anyone has any info. This is the last issue for my project. If I will solve this then it gets successfully completed. So its really important for me..

      Thanks a ton in advance..

        • 1. Re: How to compare with previous value?
          Manikandan-S-Oracle

          Try this:

           

          <?COLUMNx[not(.=preceding::COLUMNx)]?>

           

          where COLUMNx is the filed element you want to include.

           

          1. 'not()' - looking for a false boolean value to be returned expression

          2.  '.=preceding::COLUMNx'

                - the '.' is a reference to the current element i.e. COLUMNx in the current record of the tree

                - preceding::COLUMNx refers to the value of COLUMNx in the previous row of data.

           

          Now, what do you want to do if current row value matches with the previous value?

          • 2. Re: How to compare with previous value?
            sfr.farhan

            Sample

             

            XML

             

            <?xml version="1.0" encoding="UTF-8"?>

            <ROOT>

            <ROW>

            <START_DATE>01-01-1980</START_DATE>

            <END_DATE>01-01-1988</END_DATE>

            </ROW>

            <ROW>

            <START_DATE>01-01-1988</START_DATE>

            <END_DATE>01-01-1990</END_DATE>

            </ROW>

            <ROW>

            <START_DATE>01-01-2000</START_DATE>

            <END_DATE>01-01-2005</END_DATE>

            </ROW>

            </ROOT>

             

            Layout

             

            <?for-each:/ROOT/ROW?>
            ==================
            Current StartDate <?START_DATE?
            >
            Current End Date <?END_DATE
            ?>
            Next Start Date <?following-sibling::ROW/
            START_DATE?>
            Previous End Date <?preceding-sibling::ROW[1]/END_DATE
            ?>
            ================
            <?end for-each
            ?>

             

            Check the following, it may help you or provide some hint atleast

            http://winrichman.blogspot.com/2008/10/previous-next-element.html

            • 3. Re: How to compare with previous value?
              2687447

              Thanks For your rply..

              Sibling is working but the problem is its giving previous values from XML which is not sorted. I sorted that data and according to that it should give previous values. Requirement is to get preceding values depending upon table not XML data. If have something about this plz share..

              Thanks a million in advance..

              • 4. Re: How to compare with previous value?
                sfr.farhan

                Is it not possible to get sorted data by query itself, in this way, you can better apply logic (get preceding value based on xml rather than table)

                because logic provided in my post based on XML data

                 

                Note sure: else you need to manage processing with variable.

                • 5. Re: How to compare with previous value?
                  AlexAnd

                  I sorted that data and according to that it should give previous values.

                  ok, you sorted xml data but what do you mean by

                  Requirement is to get preceding values depending upon table not XML data.

                  not clear

                   

                  is the table based on xml data also ? or not ?

                   

                  what if you have xml data and then sort it by some field

                  <?sort:VALUE_FOR_SORTING;'ascending';data-type='text'?>

                  before display it ?

                  • 6. Re: How to compare with previous value?
                    sfr.farhan

                    AlexAnd wrote:

                     

                    what if you have xml data and then sort it by some field

                    <?sort:VALUE_FOR_SORTING;'ascending';data-type='text'?>

                    before display it ?

                     

                    As per my observation, sorting syntax still have no impact as per provided sample.

                    I tried below sample with <?sort:END_DATE;'ascending';data-type='date'?> but process run based on actual XML data for Next Start Date and Previous End Date, even data is sorted at runtime.

                     

                    sfr.farhan.fani wrote:


                    Sample

                     

                    XML

                     

                    <?xml version="1.0" encoding="UTF-8"?>

                    <ROOT>

                    <ROW>

                    <START_DATE>01-01-1980</START_DATE>

                    <END_DATE>01-01-1988</END_DATE>

                    </ROW>

                    <ROW>

                    <START_DATE>01-01-1988</START_DATE>

                    <END_DATE>01-01-1990</END_DATE>

                    </ROW>

                    <ROW>

                    <START_DATE>01-01-2000</START_DATE>

                    <END_DATE>01-01-2005</END_DATE>

                    </ROW>

                    </ROOT>

                     

                    Layout

                     

                    <?for-each:/ROOT/ROW?>
                    ==================
                    Current StartDate <?START_DATE?
                    >
                    Current End Date <?END_DATE
                    ?>
                    Next Start Date <?following-sibling::ROW/
                    START_DATE?>
                    Previous End Date <?preceding-sibling::ROW[1]/END_DATE
                    ?>
                    ================
                    <?end for-each
                    ?>

                     

                     

                    What I feel, first data should be sorted in query itself in order to process data as per above sample, else need to see any other method.

                    • 7. Re: How to compare with previous value?
                      AlexAnd

                      What I feel, first data should be sorted in query itself in order to process data as per above sample,

                      looks like it's the simplest way

                       

                      else need to see any other method.

                      one moment please

                       

                      what about

                      - for excel template we can use pre-process by xslt

                      - for rtf template we can also use xslt for changing something

                      - using variable

                      Note sure: else you need to manage processing with variable.

                      look at

                       

                      by variable

                      <xsl:variable name="sortedSet">

                        <xsl:for-each select="ROOT/ROW">

                          <xsl:sort select="END_DATE" />

                          <xsl:copy-of select="." />

                      </xsl:for-each>

                      </xsl:variable>


                      <?for-each:$sortedSet?>

                      <?for-each:ROW?>

                      -- new ROW:

                      Current StartDate <?START_DATE?>

                      Current End Date <?END_DATE?>

                      Next Start Date <?following-sibling::ROW/START_DATE?>

                      Previous End Date <?preceding-sibling::ROW[1]/END_DATE?>

                      <?end for-each?>

                      <?end for-each?>


                      sample xml

                      <?xml version="1.0" ?>

                      <ROOT>

                          <ROW>

                              <START_DATE>1980-01-01</START_DATE>

                              <END_DATE>1988-01-01</END_DATE>

                          </ROW>   

                          <ROW>

                              <START_DATE>2000-01-01</START_DATE>

                              <END_DATE>2005-01-01</END_DATE>

                          </ROW>

                          <ROW>

                              <START_DATE>1988-01-01</START_DATE>

                              <END_DATE>1990-01-01</END_DATE>

                          </ROW>

                      </ROOT>


                      and result


                      by variable

                       

                      -- new ROW:

                      Current StartDate 1980-01-01

                      Current End Date 1988-01-01

                      Next Start Date 1988-01-01

                      Previous End Date

                      -- new ROW:

                      Current StartDate 1988-01-01

                      Current End Date 1990-01-01

                      Next Start Date 2000-01-01

                      Previous End Date 1988-01-01

                      -- new ROW:

                      Current StartDate 2000-01-01

                      Current End Date 2005-01-01

                      Next Start Date

                      Previous End Date 1990-01-01

                      it's also should works for your test case of xml

                       

                       

                      2687447

                      check above test case please

                      is it works for you ?

                      • 8. Re: How to compare with previous value?
                        sfr.farhan

                        Thanks AlexAnd, you made it..!! possible and provide the right way.

                        Yes, it's working for me as well.

                        • 9. Re: How to compare with previous value?
                          2687447

                          thanx guys.. U guys are awsome.. I have learnt so much from this Community.. As a newbie I never felt helpless because of you.. Thank you very much..

                          Bt I am facing very small issue. where should I give this comment cause  in my scenario I have table which is already grouped by another value. So I am not able to understand it. Please provide some input so that I can campletey overcome this issue.

                          Thanks in advance.

                           

                          <xsl:variable name="sortedSet">

                            <xsl:for-each select="ROOT/ROW">

                              <xsl:sort select="END_DATE" />

                              <xsl:copy-of select="." />

                          </xsl:for-each>

                          </xsl:variable

                          <?for-each:$sortedSet?>

                          <?for-each:ROW?>

                          -- new ROW:

                          Current StartDate <?START_DATE?>

                          Current End Date <?END_DATE?>

                          Next Start Date <?following-sibling::ROW/START_DATE?>

                          Previous End Date <?preceding-sibling::ROW[1]/END_DATE?>

                          <?end for-each?>

                          <?end for-each?>

                          • 10. Re: How to compare with previous value?
                            sfr.farhan

                            plz share your xml and template in order to examine existing grouping and ordering.

                            • 11. Re: How to compare with previous value?
                              AlexAnd

                              may be DepositFiles depositfiles.com

                              so share and post link and anyone can try to help you

                              • 12. Re: How to compare with previous value?
                                sfr.farhan

                                you can share here, part of your logic as a sample with xml source and layout tags.

                                • 13. Re: How to compare with previous value?
                                  sfr.farhan

                                  is it possible to share like below ref example. see layout, fields and xml in my reply

                                  how to spanne row / single heading for similar group of rows

                                  • 14. Re: How to compare with previous value?
                                    2687447

                                    Ok np..

                                    Now sippose I am Having following XML.

                                     

                                    < Objects>

                                    < Object>

                                    < StartTime>2014-05-09T09:00:00</StartTime>

                                    < FinishTime>2014-05-09T16:00:00</ FinishTime>

                                    </ Object>

                                    < Object>

                                    < StartTime>2014-05-09T08:00:00</StartTime>

                                    < FinishTime>2014-05-09T08:30:00</ FinishTime>

                                    </ Object>

                                    < Object>

                                    < StartTime>2014-05-09T07:00:00</ StartTime>

                                    < FinishTime>2014-05-09T07:30:00</ FinishTime>

                                    </ Object>

                                    < Object>

                                    < StartTime>2014-05-08T12:00:00</ StartTime>

                                    < FinishTime>2014-05-08T12:30:00</ FinishTime>

                                    </ Object>

                                    < Object>

                                    < StartTime>2014-05-08T08:00:00</ StartTime>

                                    < FinishTime>2014-05-08T16:00:00</ FinishTime>

                                    </ Object>

                                    < Object>

                                    < StartTime>2014-05-07T12:00:00</ StartTime>

                                    < FinishTime>2014-05-07T12:30:00</ FinishTime>

                                    </ Object>

                                    < Object>

                                    < StartTime>2014-05-07T08:00:00</ StartTime>

                                    < FinishTime>2014-05-07T16:00:00</ FinishTime>

                                    </ Object>

                                    < Object>

                                    < StartTime>2014-05-05T08:00:00</ StartTime>

                                    < FinishTime>2014-05-05T16:00:00</ FinishTime>

                                    </ Object>

                                    < Object>

                                    < StartTime>2014-05-06T08:00:00</ StartTime>

                                    < FinishTime>2014-05-06T11:30:00</ FinishTime>

                                    </ Object>

                                    < Object>

                                    < StartTime>2014-05-06T13:00:00</ StartTime>

                                    < FinishTime>2014-05-06T17:30:00</ FinishTime>

                                    </ Object>

                                    </ Objects>

                                     

                                    Now I need to sort data according to the StartTime. So grouped by StartTime sorted two times by StartTime so that within group also it can show sorted result. So I prepared rtf as below.

                                     

                                    group Object by StartTime

                                    Date

                                    Start

                                    End

                                    F StartTime1

                                    StartTime

                                    FinishTime E

                                    end Object by StartTime

                                     

                                    group Object by StartTime<?for-each-group:ReportData/Objects[position( ) >=2]/Object;xdoxslt:left(./StartTime,10)?><?sort:current-group()/StartTime;'ascending';data-type='text'?>

                                    F - <?for-each:current-group()?><?sort:xdoxslt:left(xdoxslt:right(StartTime,8),5);'ascending';data-type='text'?>

                                    StartTime1 - <?xdoxslt:left(StartTime,10)?> --- To get Date only.

                                    StartTime - <?xdoxslt:xdo_format_date($_XDOXSLTCTX, StartTime,' HH:MIAM’)?>

                                                         “To display in ‘AM’ ‘PM’ format”

                                    FinishTime - <?xdoxslt:xdo_format_date($_XDOXSLTCTX, FinishTime,' HH:MIAM’)?>

                                    E - <?end for-each?>

                                    end Object by StartTime  - <?end for-each-group?>

                                     

                                    This will give me –

                                    Date

                                    Start

                                    End

                                    5/5/2014

                                    8:00AM

                                    4:00PM

                                     

                                    5/6/2014

                                    8:00AM

                                    11:30AM
                                    5/6/20141:00PM

                                    5:30PM

                                     

                                    5/7/20148:00AM

                                    4:00PM

                                    5/7/201412:00PM

                                    12:30PM

                                     

                                    5/8/20148:00AM

                                    4:00PM

                                    5/8/201412:00PM

                                    12:30PM

                                    5/9/20147:00am7:30AM
                                    5/9/20148:00AM8:30AM
                                    5/9/20149:00AM4:00PM

                                     

                                    Requirement –

                                    We need shade those records which are overlapping i.e. If the Finishtime of the first row > the Starttime of the next row then they are overlapping. So above two records should look like below.

                                     

                                    5/7/2014

                                    8:00AM

                                    4:00PM

                                    5/7/2014

                                    12:00PM

                                    12:30PM

                                     

                                    5/8/2014

                                    8:00AM

                                    4:00PM

                                    5/8/2014

                                    12:00PM

                                    12:30PM

                                     

                                    Just need to compare previous value. I tried with your previous solution but its not working in this condition. So please provide some input on this. This issue is really messing up with me from last 3-4 days.

                                    Thanks a million in advance.

                                    1 2 Previous Next