Altova StyleVision 2024 Basic Edition

If the source document contains nodes that take date values, using the xs:date or xs:dateTime datatypes in the underlying XML Schema makes available the powerful date and time manipulation features of XPath 2.0/3.0 (see examples below). StyleVision supports the xs:date or xs:dateTime datatypes by providing a wide range of date formatting possibilities via the Input Formatting feature.

 

Note:Date and time data cannot be manipulated with XPath 1.0. However, with XPath 1.0 you can still use Input Formatting to provide date formatting.

 

 


 

 

Date calculations with XPath 2.0

Data involving dates can be manipulated with XPath 2.0 expressions in Auto-Calculations. Given below are a few examples of what can be achieved with XPath 2.0 expressions.

 

The XPath 2.0 functions current-date() and current-dateTime() can be used to obtain the current date and date-time, respectively.

Dates can be subtracted. For example: current-date() - DueDate would return an xdt:dayTimeDuration value; for example, something like P24D, which indicates a positive difference of 24 days.

Time units can be extracted from durations using XPath 2.0 functions. For example: days-from-duration(xdt:dayTimeDuration('P24D')) would return the integer 24.

 

Here is an XPath 2.0 expression in an Auto-Calculation. It calculates a 4% annual interest on an overdue amount on a per-day basis and returns the sum of the principal amount and the accumulated interest:

 

 if                (current-date() gt DueDate)

 then        (round-half-to-even(InvoiceAmount +

                         (InvoiceAmount*0.04 div 360 *        
                                 days-from-duration((current-date() - DueDate))), 2))

 else        InvoiceAmount

 

Such a calculation would be possible with XPath 2.0 only if the DueDate element were defined to be of a date type such as xs:date and the content of the element is entered in its lexically correct form, that is, YYYY-MM-DD[±HH:MM], where the timezone component (prefixed by ±) is optional.

 

© 2017-2023 Altova GmbH