[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Date Difference

Subject: RE: Date Difference
From: "Haarman, Michael" <mhaarman@xxxxxxxxx>
Date: Mon, 19 Dec 2005 16:11:34 -0600
xsl value of select date
I think your making it harder that it need be.  Here is the meat in the
stylesheet I posted.  The tricky part is the single digit month, so I pad
the data if its short:

    <xsl:variable name="earlierPadded">
      <xsl:choose>
        <xsl:when test="fn:string-length(substring-before(date[1], '/')) =
1">
          <xsl:value-of select="concat('0',date[1])"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="date[1]"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>

Substitute the XPath to your datapoints for *data[1]*

Once the string is regularized, the regex features of xslt2 make building a
string in standard date format simple:

    <xsl:variable name="regexE" 
      select="xs:date(fn:replace($earlierPadded, '(.*)/(.*)/(.*)',
'$3-$1-$2'))"/>

This takes the padded string, breaks out the mm, dd and yyyy parts and
reorders them around dash characters.  It then casts the string to xs:date
datatype, over which a unique brand of magical date arithmetic can
performed.

Once you have corrected strings cast to xs:date datatypes, just do the
strange and wonderful math:

      <xsl:value-of select="$later - $earlier"/>

HTH,

Mike


> -----Original Message-----
> From: thomas.maciejewski@xxxxxxxxx 
> [mailto:thomas.maciejewski@xxxxxxxxx]
> Sent: Monday, December 19, 2005 3:57 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: RE:  Date Difference
> 
> 
> I wrote this:
> 
>       <xsl:function name="sgfr:IsDateGreater">
>             <xsl:param name="stringDate1"/>
>             <xsl:param name="stringDate2"/>
>             <xsl:variable name="tokenizedDate1"
> select="tokenize($stringDate1, '/')"/>
>             <xsl:variable name="monthPart1"
> select="subsequence(($tokenizedDate1), 1, 1)"/>
>             <xsl:variable name="datePart1"
> select="subsequence(($tokenizedDate1), 2, 1)"/>
>             <xsl:variable name="yearPart1"
> select="subsequence(($tokenizedDate1), 3, 1)"/>
>             <xsl:variable name="tokenizedDate2"
> select="tokenize($stringDate2, '/')"/>
>             <xsl:variable name="monthPart2"
> select="subsequence(($tokenizedDate2), 1, 1)"/>
>             <xsl:variable name="datePart2"
> select="subsequence(($tokenizedDate2), 2, 1)"/>
>             <xsl:variable name="yearPart2"
> select="subsequence(($tokenizedDate2), 3, 1)"/>
>             <xsl:choose>
>                   <xsl:when test="yearPart1>yearPart2"><xsl:value-of
> select="true"/></xsl:when>
>                   <xsl:when test="yearPart1=yearPart2">
>                         <xsl:choose>
>                               <xsl:when test="monthPart1>monthPart2">
>                                     <xsl:value-of select="true"/>
>                               </xsl:when>
>                               <xsl:when test="monthPart1=monthPart2">
>                                     <xsl:choose>
>                                           <xsl:when
> test="datePart1>datePart2"><xsl:value-of select="true"/></xsl:when>
>                                           <xsl:otherwise><xsl:value-of
> select="false"/></xsl:otherwise>
>                                     </xsl:choose>
>                               </xsl:when>
>                               <xsl:otherwise><xsl:value-of
> select="false"/></xsl:otherwise>
>                         </xsl:choose>
>                   </xsl:when>
>                   <xsl:otherwise><xsl:value-of
> select="false"/></xsl:otherwise>
>             </xsl:choose>
>       </xsl:function>
> 
> Will this work?
> Or am I totally missing the point?
> 
> Regards,
> 
> 
> Tom Maciejewski
> 
> 
> **************************************************************
> ***********
> This message and any attachments (the "message") are confidential and
> intended solely for the addressees.
> Any unauthorised use or dissemination is prohibited. 
> E-mails are susceptible to alteration.   
> Neither SOCIETE GENERALE nor any of its subsidiaries or affiliates 
> shall be liable for the message if altered, changed or falsified. 
> 
> **************************************************************
> ***********

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.