Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 9th, 2012  |  syntax: None  |  size: 1.12 KB  |  hits: 30  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. calculate age in xslt from birthday
  2. xs:dateTime(actual-arrival) - xs:dateTime(xs:date(due-date))
  3.        
  4. <div id="mydate"></div>
  5.  
  6. <script type="text/javascript">
  7. <![CDATA[
  8.  
  9.       function datejs(datexslt) {
  10.         var date = datexslt.split('T')[0].split('-');
  11.         var time = datexslt.split('T')[1].split(':');
  12.         return new Date(date[1] + '/' + date[2] + '/' + date[0] + ' ' + time[0] + ':' + time[1] + ':' + time[2].substr(0, 2) + ' UTC');
  13.       }
  14.  
  15.       var utc = datejs(']]><xsl:value-of select="@PublishedDate" /><![CDATA[');
  16.  
  17.       //$('#mydate').text(utc);
  18.  
  19. ]]>
  20. </script>
  21.        
  22. <xsl:variable name="Age">
  23.     <xsl:choose>
  24.         <xsl:when test="month-from-date(current-date()) > month-from-date($Birthday) or month-from-date(current-date()) = month-from-date($Birthday) and day-from-date(current-date()) >= day-from-date($Birthday)">
  25.             <xsl:value-of select="year-from-date(current-date()) - year-from-date($Birthday)" />
  26.         </xsl:when>
  27.         <xsl:otherwise>
  28.             <xsl:value-of select="year-from-date(current-date()) - year-from-date($Birthday) - 1" />
  29.         </xsl:otherwise>
  30.     </xsl:choose>
  31. </xsl:variable>