Altova StyleVision 2024 Professional 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:


1.A graphical date picker to help Authentic View users enter dates in the correct lexical format of the datatype for that node. The date picker, since it is intended for data input, is available only in Authentic View.

2.A wide range of date formatting possibilities via the Input Formatting feature.


These StyleVision features are described in the sub-sections of this section: Using the Date-Picker and Formatting Dates. In the rest of the  introduction to this section, we show how XPath 2.0 can be used to make calculations that involve dates.


Note:Date and time data cannot be manipulated with XPath 1.0. However, with XPath 1.0 you can still use the Date Picker to maintain data integrity and 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. Using the Date Picker ensures that the date is entered in the correct lexical form.


© 2018-2024 Altova GmbH