Connecting Tech Pros Worldwide Help | Site Map

XSL Date calculation

Newbie
 
Join Date: Sep 2009
Posts: 18
#1: Sep 14 '09
Q)How to do the calculation for a date?

Solution applied -->
Defining a template
xsl:template match="DBE:Object" mode="TestTable"

Delivery Date

Latest Possible Order Date

xsl:apply-templates - select="DBE:Attribute[@name='DeliveryDate']/DBE:Date/>

xsl:apply-templates select="DBE:Attribute[@name='LatestOrderDate']"/>


Now i want to calculate "LatestOrderDate" = "DeliveryDate" - 42 days. How should i do it?
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,631
#2: Sep 14 '09

re: XSL Date calculation


pretty much as you desribed it: "LatestOrderDate" = "DeliveryDate" - 42
Newbie
 
Join Date: Sep 2009
Posts: 18
#3: Sep 14 '09

re: XSL Date calculation


Well,
If the date format for "DeliveryDate" is 2006-01-01 then to calculate "LatestOrderDate" we need to first take out month, day and year and then reduce one month and 12 days.....

Now here Day(Date)=1
so, to reduce 42 we need to reduce the month (exactly 30 days first) from Jan to Dec and then need to calculate by reducing 12 in the month of Nov. So, how to implement the logic as to whatever might be the date entererd for "DeliveryDate"?
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,631
#4: Sep 14 '09

re: XSL Date calculation


there are some useful string and number functions in XPath, that you can use. try to assign that value to a variable.
Newbie
 
Join Date: Sep 2009
Posts: 18
#5: Sep 16 '09

re: XSL Date calculation


I am getting the date by traversing through the rows of a table. The moment i get a column (Delivery Date) of that row , i need to reduce 42 from it and display the "Latest Order Date".

Expand|Select|Wrap|Line Numbers
  1.  
  2. <xsl:for-each select="DBE:Attribute[@name='TestTable']/DBE:Table/DBE:TableRow"> 
  3. <tr>
  4.  <xsl:for-each select="child::DBE:TableData[count(preceding-sibling::DBE:TableData)+1=1]"> 
  5. <td> <xsl:apply-templates/> <!-- I get the Delivery Date here --> </td> 
  6. </xsl:for-each> 
  7. <td> LatestOrderDate </td> 
  8.  
Please let me know incase of any example to do so.
Also is it easy to define the logic in jsp and use it in xsl. Which way is recommended?
Reply