Project

Profile

Help

subtract-dates-xxx function not implemented?

Added by Anonymous about 17 years ago

Legacy ID: #4236596 Legacy Poster: Giulio_Buccini (giulio_buccini)

Hello to everybody, (I'm italian so I'm sorry for my english in advance) Im developing a commercial product based upon Saxon (I use saxon8.8 and Java 1.5.0) and yesterday i tested following innocent xslt sentence: <xsl:template match="/"> <xsl:apply-templates/> <xsl:message> <xsl:value-of select=" subtract-dates-yielding-dayTimeDuration( xs:date('2007-04-26'), xs:date('2007-04-25')) "/> </xsl:message> </xsl:template> (nothing magic, it simply print-out difference between April 26 and April 25 as DayTimeDuration) and... big surprise for me! I received following message: XPST0017: XPath syntax error at char 86 on line 29 in {...4-26'), xs:date('2007-04-25...}: Unknown system function subtract-dates-yielding-dayTimeDuration() Unknown function?? So seems to me as standard XSLT2.0 function "subtract-dates-yielding-dayTimeDuration" is not implemented by Saxon... :( Is this right? By the way, I get the same result when I try all the other similar functions: subtract-dates-yielding-dayTimeDuration subtract-dates-yielding-yearMonthDuration subtract-dateTimes-yielding-dayTimeDuration subtract-dateTimes-yielding-yearMonthDuration As I discovered today, above functions are not listed in the function-library list on Saxonica website... and there is no Saxon extension that can I use to fill the gap... Somebody knows if future versions will implement subtract-dates-XXX functions? They are so useful... (and they are listed at page 793 of "XSLT 2.0" - 3rd ed. book by Michael Kay) Giulio Buccini


Replies (5)

Please register to reply

RE: subtract-dates-xxx function not implement - Added by Anonymous about 17 years ago

Legacy ID: #4237681 Legacy Poster: Michael Kay (mhkay)

These functions disappeared between the time the book went to press and the final XSLT 2.0 Recommendation. You can use the "-" operator to subtract dates or dateTimes to get a dayTimeDuration, for example xs:date('2007-04-26') - xs:date('2007-04-25') The option to get the difference between two dates in months or years disappeared because no-one could agree on exactly how it should be defined, for example what should be the result of 2004-02-29 minus 2004-01-31. So you have to define your own function, which can implement whatever you think the right semantics are. Regards Michael Kay

RE: subtract-dates-xxx function not implemented? - Added by Anonymous about 17 years ago

Legacy ID: #4239470 Legacy Poster: Giulio_Buccini (giulio_buccini)

Thanks for your fast answer and solution you proposed. I will do so. Giulio Buccini

RE: subtract-dates-xxx function not implemented? - Added by Anonymous over 16 years ago

Legacy ID: #4609080 Legacy Poster: Colin Green (colgreen)

So to confirm. We have the need to calculate a person's age in years based on their date of birth and today's date. And then say, ensuring it is 18 or more. So we can determine if they are 18 or over with something like: (xs:date("1989-11-06") + xs:yearMonthDuration("P18Y")) <= current-date() But there is no direct way of actually calculating the age? e.g. so that we can store the result in a variable and re-use it. Cheers, Colin Green

RE: subtract-dates-xxx function not implement - Added by Anonymous over 16 years ago

Legacy ID: #4609119 Legacy Poster: Michael Kay (mhkay)

Correct, there is no direct way to calculate someone's age in years by subtracting two dates. Sounds like a candidate for a third-party function library. Suggestion: extract the year components of the two dates, subtract giving $A; if birth date + $a*yearMonthDuration('P1Y') < current-date() then age is $A else age is $A - 1.

RE: subtract-dates-xxx function not implemented? - Added by Anonymous over 16 years ago

Legacy ID: #4612626 Legacy Poster: Colin Green (colgreen)

Thanks. We have indeed implemented our own function to do this as calculating ages is quite a common requirement for us.

    (1-5/5)

    Please register to reply