Date Comparision in XSL

Hi ,
I have a requirement where i need to take the Earliest and Last date time among DateTime Item nodes .
i/p:
<Order>
<line>
<Date1></Date1>
<Date2></Date2>
</line>
<line>
<Date1></Date1>
<Date2></Date2>
</line>
<line>
<Date1></Date1>
<Date2></Date2>
</line>
</Order>
O/P: earliest Date among all the Date1 nodes and Lease Date among all Date2 nodes in Order tag .
Let me know if any one has worked on similar requirement .
Regards ,
Mohan

you could use xsl to do this (although it doesn't work one some string dates i tested
see :
http://www.deez.info/sengelha/category/programming/xml/xpath/
Selecting A Maximum Value Using XPath
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
      <xsl:for-each select="/Order/line">
      <xsl:sort select="Date1" order="descending" />
      <xsl:if test="position() = 1">
        <xsl:value-of select="Date1"/>
        </xsl:if>
        <br></br>
      </xsl:for-each>
    <xsl:value-of select="/Order/line[not(preceding-sibling::line/Date1 > Date or following-sibling::line/Date1 > Date)]"/>
</xsl:template>
</xsl:stylesheet>maybe you first need to 'format' the date to some other format so it can do a good sort on it.
maybe the sample helps you a bit

Similar Messages

  • Date function in XSL

    Hi,
    I am inserting XML data into database using XSL
    XML File
    <Employee_details>
         <Emp_cd>E002</Emp_cd>
         <Emp_name>Puneet</Emp_name>
         <Emp_DOB>12-dec-90</Emp_DOB>
         <Emp_Height>6.1</Emp_Height>
         <Emp_address>Aundh</Emp_address>
         <Emp_Desgn>TL</Emp_Desgn>
         <Emp_Salary>370000</Emp_Salary>
         <Emp_Dept>EDP</Emp_Dept>
         <Emp_DOJ>12-mar-07 03:30</Emp_DOJ>
    </Employee_details>
    XLS File:
    <?xml version="1.0"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
         <xsl:template match="/Employee">
              <ROWSET>
              <xsl:for-each select="Employee_details">
                   <ROW>
                        <EMP_CD>
                             <xsl:value-of select="Emp_cd"/>
                        </EMP_CD>
                        <EMP_DESGN>
                             <xsl:value-of select="Emp_Desgn"/>
                        </EMP_DESGN>
                        <EMP_SALARY>
                             <xsl:value-of select="Emp_Salary"/>
                        </EMP_SALARY>
                        <EMP_DEPT>
                             <xsl:value-of select="Emp_Dept"/>
                        </EMP_DEPT>
                        <EMP_DOJ>
                             <xsl:value-of select="Emp_DOJ"/>
                        </EMP_DOJ>
                   </ROW>
              </xsl:for-each>
              </ROWSET>
         </xsl:template>
    </xsl:stylesheet>
    i am sucessfully inserting date into table in format of dd-Mon-YYYY. but whenever i am trying to inserting the date in format dd-Mon-YYYY hh:mi its giving error like parsing xml file
    i tried to change the date format in XSL like
    <EMP_DOJ>
    <xsl:value-of select="xs:dateTime(Emp_DOJ,''dd-Mon-YYYY hh:mi'')"/>
    </EMP_DOJ>
    but its not working as well,
    whenever we have to insert the datetime value in table we have to use
    to_date(emp_jod,'dd-Mon-YYYY hh:mi') but how it implement in XSL

    Does this help?
    SQL> CREATE TABLE emp_test (
      2   emp_cd     VARCHAR2(10),
      3   emp_desgn  VARCHAR2(30),
      4   emp_salary NUMBER,
      5   emp_dept   VARCHAR2(3),
      6   emp_doj    DATE
      7  );
    Table created
    SQL> DECLARE
      2 
      3   xml_data xmltype :=
      4   xmltype('<Employee_details>
      5  <Emp_cd>E002</Emp_cd>
      6  <Emp_name>Puneet</Emp_name>
      7  <Emp_DOB>12-dec-90</Emp_DOB>
      8  <Emp_Height>6.1</Emp_Height>
      9  <Emp_address>Aundh</Emp_address>
    10  <Emp_Desgn>TL</Emp_Desgn>
    11  <Emp_Salary>370000</Emp_Salary>
    12  <Emp_Dept>EDP</Emp_Dept>
    13  <Emp_DOJ>12-mar-07 03:30</Emp_DOJ>
    14  </Employee_details>');
    15 
    16   xsl_data xmltype :=
    17   xmltype('<?xml version="1.0"?>
    18  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    19  <xsl:template match="/">
    20  <ROWSET>
    21  <xsl:for-each select="Employee_details">
    22  <ROW>
    23  <EMP_CD><xsl:value-of select="Emp_cd"/></EMP_CD>
    24  <EMP_DESGN><xsl:value-of select="Emp_Desgn"/></EMP_DESGN>
    25  <EMP_SALARY><xsl:value-of select="Emp_Salary"/></EMP_SALARY>
    26  <EMP_DEPT><xsl:value-of select="Emp_Dept"/></EMP_DEPT>
    27  <EMP_DOJ><xsl:value-of select="Emp_DOJ"/></EMP_DOJ>
    28  </ROW>
    29  </xsl:for-each>
    30  </ROWSET>
    31  </xsl:template>
    32  </xsl:stylesheet>');
    33 
    34   v_context DBMS_XMLStore.ctxType;
    35   v_rows    NUMBER;
    36 
    37  BEGIN
    38 
    39   -- change session nls to handle implicit conversion from date string :
    40   execute immediate 'alter session set nls_date_format = ''dd-mon-rr hh24:mi''';
    41 
    42   v_context := DBMS_XMLStore.newContext('EMP_TEST');
    43   v_rows := DBMS_XMLStore.insertXML(v_context, xml_data.transform(xsl_data));
    44   DBMS_XMLStore.closeContext(v_context);
    45 
    46  END;
    47  /
    PL/SQL procedure successfully completed
    SQL> select * from emp_test;
    EMP_CD     EMP_DESGN                      EMP_SALARY EMP EMP_DOJ
    E002       TL                                 370000 EDP 12/03/2007 03:30:00If it's important for you, you may store the previous nls setting and reset it after loading.
    Erm... wait... It won't work if you try to load "emp_DOB" in the same time.
    I guess you'll have to ensure that all date strings come with the same format.
    You can do that in the XSL :
    <EMP_DOB><xsl:value-of select="concat(Emp_DOB,'' 00:00'')"/></EMP_DOB>Edited by: odie_63 on 30 juil. 2010 11:52
    Edited by: odie_63 on 30 juil. 2010 12:00

  • Date comparision not working in BI-Publisher in one scenario.

    Hi,
    Iam using sqlquery as a datamodel for BI-Publisher report. I have a requirement that the input parameters startdate and endate are Date types. When the user enters startdate and enddate and clicks on view, the report should show data which falls in between those dates.
    Here is the sample query i used.
    select * from
    table1
    where begintime >= :p_StartDate and begintime <=:p_EndDate
    Here begintime is a timestamp and p_StartDate and p_EndDate are just dates. So when comparing begintime with p_StartDate/p_EndDate, i guess its taking default time from that date and because of that the comparision is failing in 1 case. i.e, In the above query, though the comparision operator is >= or <= , ultimately > or < is getting effective. So to acheive the actual result, I need to give one day more for start and end dates.
    However I found a way to acheive this without adding extra day to both the dates. Here it is :
    select * from table1 where
    ( begintime >= to_timestamp(to_char(:p_StartDate) || '00 00 00', 'DD Mon YYYY HH24 MI SS')) and
    ( begintime <= to_timestamp(to_char(:p_EndDate) || '23 59 59', 'DD Mon YYYY HH24 MI SS'))
    But the above is working in sqleditor like jdeveloper database navigator. But not working in BI-Publisher.
    BI-Publisher is throwing error saying
    "ORA-01830: date format picture ends before converting entire input string"
    Please help as to how to go about this problem or any alternative solution.
    Thanks & Regards,
    -Vijay-

    Hi,
    I think it will be fine to trunc the begin time since :p_StartDate and p_EndDate are just dates without time stamp
    i.e:
    select * from
    table1
    where trunc(begintime) >= :p_StartDate and trunc(begintime) <=:p_EndDate;
    any problem with this.Please share the thought.
    Best Regards,
    mahi

  • SQL data transformed by XSL-TEXT template

    Hi,
    please, how can I transform data retrived by SQL query using XSL-TEXT template (need to generate text file using rpad/lpad XSL function)? There is no problem if the data set is 'XML file', with setting the data set as SQL querry I'm lost..
    Thanks for all replies.
    Rad

    Hi,
    problem solved by using data template.
    Rad

  • Sql date comparision

    hello
    i am using oracle 8.1.7..i am new to oracle
    i have a date column in the table, i need to get this date and check whether this date is a sunday or saturday, if they are i need to make this date to next business day (i.e monday-friday),
    i also need to check whether this date falls on last day of month and then make this date as next month first day.
    i am able to write a pl/sql program and compare the date using to_char(date,'d') and last_day(date).
    can this be achieved in a sql select statement.
    actually this date needs to be concatened with other values i am getting from the table. other values i am getting in select statement using ||..
    i tried but i could not find how i could create a if then comparision in a sql select statement.
    please give any suggestions...
    thanks in advance...

    These two expressions should do the date conversions. How you combine them depends which one you want to do first and what the rest of your query looks like
    date + decode(to_char(date,'DY'),'SAT',2,'SUN',1,0)
    date + decode(to_char(date+1,'DD'),'01',1,0)

  • Issue with Date Comparision

    Hi Buddies,
    I explain the scenario,
    I have an dunning letter statement report which basically run for the three remainders (1,2,3) to the customer.
    If the remainder 3 runs , i want to display the pervious remainder dates of 1 and 2 in my report.
    If the remainder 2 runs, i want to display the pervious remainder date of 1 in my report.
    I have date column in the dunning letter history table as Dunning_Date.
    How can we achive this in sql?. I am getting struck over here, please give your advice to do it.
    Regards
    Ram

    Is this really an SQL question or are you looking for a solution in Reports? If so you should ask this in the Reports

  • Date comparision issue in the report

    Hi Buddies,
    I explain the scenario,
    I have an dunning letter statement report which basically run for the three remainders (1,2,3) to the customer.
    If the remainder 3 runs , i want to display the pervious remainder dates of 1 and 2 in my report.
    If the remainder 2 runs, i want to display the pervious remainder date of 1 in my report.
    I have date column in the dunning letter history table as Dunning_Date.
    How can we achive this in sql?. I am getting struck over here, please give your advice to do it.
    Regards
    Ram

    I think your date format is in different format with the date format u stored in presentation variable so better check the date format of the case function u wrote it in you variable that will solve the problem.

  • Please help me to solve this date comparision issue..

    Please help me to solve this issue..
    If i have some data like the following..
    ID           START DATE             END DATE
    1             20080101              20080501
    1             20080502              20080630
    2             20080631              20080801
    2             20080802              20080901
                                                 ---------------> There is a break in date over here
    2             20080930              20081029
    2             20081030              20081130
    I need to compare the End Date with the start date (These data will not be in order)
    and find out if there is any break and should get the output date : *20080930*
    I am trying to do this in SQL or PL/SQL.Please help me .
    Thanks in advance.
    phani

    Hi Frank ,
    Sorry to bug you again. I ran your code on my actual data but not gettting the expected output.Here i am posting the actual code and the output that i got when i ran your code.Please bear with me and help me to solve this..
    /* Formatted on 5/25/2009 2:27:24 PM (QP5 v5.115.810.9015) */
    SELECT   member_nbr,
             aff_nbr,
             ymdeff,
             ymdend,
             gap_before,
             COUNT (gap_after)
                OVER (PARTITION BY member_nbr, aff_nbr ORDER BY ymdend DESC)
                AS gap_cnt
      FROM   (SELECT   member_nbr,
                       aff_nbr,
                       ymdeff,
                       ymdend,
                       CASE
                          WHEN ymdeff >
                                  LEAD(ymdend)
                                     OVER (PARTITION BY member_nbr, aff_nbr
                                           ORDER BY ymdend DESC)
                                  + 1
                          THEN
                             1
                       END
                          AS gap_before,
                       CASE
                          WHEN ymdend <
                                  LAG(ymdeff)
                                     OVER (PARTITION BY member_nbr, aff_nbr
                                           ORDER BY ymdend DESC)
                                  - 1
                          THEN
                             1
                       END
                          AS gap_after
    ------------I need this SQL to filter the whole data to the data that i posted in previous post -----
                FROM   (  SELECT   ms1.member_nbr, 
                                   ms1.aff_nbr,
                                   ms1.ymdeff,
                                   ms1.ymdend,
                                   ms1.void
                            FROM   (SELECT   ms.member_nbr,
                                             ms.aff_nbr,
                                             ms.ymdeff,
                                             ms.ymdend,
                                             ms.void
                                      FROM   MEMBER mb, member_span ms
                                     WHERE   mb.member_nbr = ms.member_nbr
                                             AND (20090523 BETWEEN ms.ymdeff
                                                               AND  ms.ymdend
                                                  AND TRIM (void) IS NULL)
                                             AND mb.member_nbr = 'A1000073000 ')
                                   eff_pcp,
                                   member_span ms1
                           WHERE   ms1.member_nbr = eff_pcp.member_nbr
                                   AND (SUBSTR (eff_pcp.aff_nbr, 1, 6) =
                                           SUBSTR (ms1.aff_nbr, 1, 6))
                        ORDER BY   ms1.ymdeff DESC)
    ---------- end of my part  ----------
                table_x) got_gaps;Outputs that i got when i ran that code for each individual members..
    Sorry to bug you frank and thanks for all the help.I will post here if i get any other data.
    Thanks
    phani

  • Date Comparision using Javascript

    hi :
    I need a help on comparing dates which is in dd-mon-yyyy format can any one help me here i have a code which is comparing the days but not the months i need some help please suggets me how to do this
    <script type="text/javascript">
    function checkdates_baseline(pStartDateItem,pEndDateItem)
    var sdate = document.getElementById(pStartDateItem).value;
    var edate = document.getElementById(pEndDateItem).value;
    if(sdate != "" && edate != "")
    var amonths = new Array('JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG','SEP','OCT','NOV','DEC');
    var start_date = new Date();
    var end_date = new Date();
    var start_month = sdate.substring(3,6);
    var end_month = edate.substring(3,6);
    var nstart_month = 0;
    var nend_month = 0;
    for(i=0;i<12;i++)
    if(amonths == start_month)
    nstart_month = i;
    if(amonths == end_month)
    nstart_month = i;
    start_date.setFullYear(sdate.substring(7,11),nstart_month,sdate.substring(0,2));
    end_date.setFullYear(edate.substring(7,11),nend_month,edate.substring(0,2));
    var result = (end_date - start_date);
    if( result <= 0)
    alert('The End date must be after the Start Date Baseline');
    document.getElementById(pEndDateItem).value = "";
    </script>
    this code is not comparing the months need help really
    thanks
    sudhir

    Hi
    I can't see why you couldn't use a PL/SQL validation - you get the dates from items on the page...?
    Anyway, the reason why you can't make my corrections work may be that they've ben "interpreted" by the markup-parser in the forum... I wasn't aware. I'll see if i can work around it. What I meant was that you needed:
    if (amonths[ i ] == ...)
    etc.
    And BTW, you've got the month-numbers wrong. January is 0 and December is 11 in JavaScript.
    Also it'd be more elegant to use an associative list. I'd write something like
    <script type="text/javascript">
    function checkdates_baseline(pStartDateItem,pEndDateItem)
      var sdate = document.getElementById(pStartDateItem).value;
      var edate = document.getElementById(pEndDateItem).value;
      if(sdate != "" && edate != "")
        var m2int = {
          JAN: 0,
          FEB: 1,
          MAR: 2,
          APR: 3,
          MAY: 4,
          JUN: 5,
          JUL: 6,
          AUG: 7,
          SEP: 8,
          OCT: 9,
          NOV: 10,
          DEC: 11 };
        var start_year = sdate.substring(7,11);
        var start_month = sdate.substring(3,6);
        var start_day = sdate.substring(0,2);
        var start_date = new Date(start_year, m2int[start_month], start_day);
        var end_year = edate.substring(7,11);
        var end_month = edate.substring(3,6);
        var end_day = edate.substring(0,2);
        var end_date = new Date(end_year, m2int[end_month], end_day);
        if( end_date <= start_date )
          alert('The End date must be after the Start Date Baseline');
          document.getElementById(pEndDateItem).value = "";
    </script>But still - try to use PL/SQL - it's probably a better way...
    HTH
    Jakob

  • Date Comparision in apex 3.0.1

    How to compare dates using this date picker collection.
    SELECT
    APEX_ITEM.DATE_POPUP(1, 1, null, 'DD-Mon-YYYY',10, 15,
    ' ','apex_date_f01_' || LPAD(rownum, 4, 0) ) "Baseline Start",
    APEX_ITEM.DATE_POPUP(2, 2, null, 'DD-Mon-YYYY',10,15,
    ' ','apex_date_f02_' || LPAD(rownum, 4, 0) ) "Baseline End"
    FROM
    DUAL
    Please suggest
    Thanks
    Sudhir

    Here is a good post on how to use JavaScript to test the name before the page is posted. http://www.oracleapplicationexpress.com/2009/04/file-browse-filename-length-limit.html
    I think the page validations get called after the internal Apex process tries to load the file data.
    Greg

  • Date Comparision in Bex

    Hi All,
    I need to calculate Avg Age.
    Avg = (X+Y)/2.
    X= 0    
          [For (current date-basic start date) <0]
       = current date-basic start date 
          [For (current date-basic start date) >0]
    Y= 0    
          [For (current date-basic finish date) <0]
       = current date-basic start date 
          [For (current date-basic finish date) >0].
    Can it be done at the query level?
    Please suggest.
    Regards,
    Sunny

    I'm not sure which key dates you need to determine age but, for instance, in FIAR cubes you could take 0NETDUEDATE and restrict by value range and choose the variable 0DAT

  • Problem in Date Comparision

    Hi,
    There is one messageTextInput in which date is being entered.
    I want to compare this date with system date and according to go in next page or throw an error.
    But when I do
    OAMessageDateFieldBean endDate = (OAMessageDateFieldBean)oawebbean.findChildRecursive("DistributionEndDate");
    Object publishRptDate1 = endDate.getValue(oapagecontext);
    String publishRptDate = publishRptDate1.toString();
    it converted in string correctly but when I try to convert into date it throws nullpointexception.
    Other thing I did is
    OAMessageDateFieldBean endDate = (OAMessageDateFieldBean)oawebbean.findChildRecursive("DistributionEndDate");
    Date compDate = endDate.getValue();
    String compDate.toString();
    In this case also it gives me nullpointexception.
    so how can I get date from the messageTextInput.
    Thanks,
    Krunal

    Hi,
    you should use this code
    first grab the sysdate
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    import java.util.Date;
    Calendar cal = Calendar.getInstance();
    Date date = Calendar.getInstance().getTime();
    DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
    String today = formatter.format(date);
    Now as you have also grabbed the date in string so just convert it Date with above format
    Date dt = formatter.parse(publishRptDate);
    now convert this date into String with above format
    String newdate = formatter.format(dt);
    Now you have two Strings today and newdate in same formats
    so now you can compare if they are equal or not very easily...
    Please let me know if you face further issues...
    Thanks,
    Gaurav

  • Date comparision

    thank you in advance
    hi i want to fetch some Employee Records from table through my class called Employee.java but i am not getting the accurate result please help me on this . for this
    i designed the database in microsoft Access in that i hava an table called Employee and in that there is one column as DOB. i declared a datatype for this as Date/Time. now i want some Employee Reocrds in between some DOB.
    for this i used "between" operator in query to fetch those records but it is not working properly .
    that means if i gave a any date from my class it is fetching all the Employee records .that is between operator is not working properly..please sugest me how can i solve this problem, is there any othere solutions please help me..
    code is shown below
    ps = con.prepareStatement("select * from tbl_Employee where 'DOB between"+(FromDate.getDate())+"' and '"+(ToDate.getDate())+"'");
    rs = ps.executeQuery();

    Use the PreparedStatement properly and learn SQL (or at least learn how to search). The way you are doing it now (cobbling together a statement, with false quoting at that, and using a PreparedStatement object to set it off) is utterly wrong.
    ps = con.prepareStatement("select * from tbl_Employee where 'DOB between" + (FromDate.getDate()) + "' and '" + (ToDate.getDate()) + "'");should be
    ps = con.prepareStatement("select * from tbl_Employee where DOB Between ? and ?");
    ps.setDate(1, FromDate.getDate());
    ps.setDate(2, ToDate.getDate());Assuming of course that whatever those Objects/Classes and methods are actually return a Date Object. If they do not, modify them to, or use SimpleDateFormat to parse them to one.

  • Data comparision bt BW and R/3: Extractor using Info Set

    Hi,
    We have a data source which is created on a R/3 Info Set. When we go to R/3 Info Set, it is using a structure.
    Now users are complaining about the data mismatch bt R/3 and BW. I am not sure how to check the R/3 data here.
    I went to SQ02, but there it is giving the structure name. I am not sure how to check the data here. Any inputs will be helpful.
    Thanks,
    Vishnu

    Hi
    You can test data between BW and R/3.
    How many fields being used on infoset? Just check the entries from both tables and check against BW system.
    Regards,
    Chandu.

  • Data comparision in 2 infocubes in 2 different systems

    Hello all,
    We have 2 3.0B BW systems. In both systems, there is a infocube called IC1.
    Now my requirement is, i have to compare the number of records, in both the cubes in 2 different BW systems. In the first BW system, we are compression/collapse the infocube every week.
    If i compare the the fact table, in the Manage-->Content tabstrip for the no of records, is it a accurate way to compare the no of records? or if there any other standard way could you please let me know?
    Many Thanks,
    Ravi

    Hi Ravi,
    try rsa1->infocube->manage->requests. See the column inserted records. But before, set the from date for the request display to a very early date.
    regards
    Siggi

Maybe you are looking for