tags:

views:

72

answers:

2

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?

A: 

You should be a little bit more verbose. If you have to stick with XSLT 1.0 I would recommed EXSLT http://www.exslt.org or the code samples from Sal Mangano's 'XSLT Cookbook' 1st edition, published by O'Reilly see www.oreilly.de/catalog/9780596003722/

If I understand it right, the first column contains the delivery date and the lastOrderDate 'll be stored into a new right column. The content of all other columns 'll be copied verbatim to output.

The idea is to first poll the content of the first column and store it into the variable deliveryDate. Afterwards the child TableData elements 'll be processed. When reaching the last TableData element a new table cell 'll be added to each table row containing the result of the calculated lastOrderDate.

See the code sample in my second answer.

xixxix
I am using XSLT 1.0 and date is defined in way - 2009-09-22
prashant rao
Using EXSLT, you can use the date:add() function template to get what you want. Simply put the deliveryDate into a variable and call:date:add( $deliveryDate, '-P42D') where -P42D is a xsd:duration literal for the desired 42 days period pointing backwards into the past.
xixxix
Can you provide some example to do so?
prashant rao
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".[CODE] <xsl:for-each select="DBE:Attribute[@name='TestTable']/DBE:Table/DBE:TableRow"> <tr> <xsl:for-each select="child::DBE:TableData[count(preceding-sibling::DBE:TableData)+1=1]"> <td> <xsl:apply-templates/> <!-- I get the Delivery Date here --> </td> </xsl:for-each> <td> LatestOrderDate </td>[/CODE]
prashant rao
A: 

"Code Sample"

<xsl:template match="DBE:Attribute[@name='TestTable']/DBE:Table/DBE:TableRow">
  <xsl:variable name="deliveryDate" select="string(DBE:TableData[position()=1])"/>
  <tr>
    <xsl:apply-templates mode="table" select="DBE:TableData">
      <xsl:with-param name="deliveryDate" select="$deliveryDate"/>
    </xsl:apply-templates>
  </tr>
</xsl:template>

<xsl:template mode="table" match="DBE:TableData">
  <xsl:param name="deliveryDate"/>
  <td>
    <xsl:value-of select="string(.)"/>
  </td>
  <xsl:if test="count(following-siblings::DBE:TableData)=0"> 
    <td>
      <xsl:value-of select="date:add( $deliveryDate, '-P42D')"/>
    </td>
  </xsl:if>
</xsl:template>
xixxix