 |
| XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

March 20th, 2017, 09:15 AM
|
|
Authorized User
|
|
Join Date: Feb 2017
Posts: 21
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Dates between
Hi,
How does XSLT calculate the number of days between these two dates?
my first date date1 and second date date2
data1: <xsl:value-of select="//n1:Invoice/cac:PaymentMeans/cbc:PaymentDueDate" disable-output-escaping="yes" />
date2: <xsl:value-of select="//n1:Invoice/cbc:IssueDate" disable-output-escaping="yes" />
i want date2-date1= ... day
How will this be spelled? Thank you..
|
|

March 20th, 2017, 09:23 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
Not sure why you are disabling output escaping for a date? Surely a date will never contain any characters that need to be escaped anyway. (Some people use disable-output-escaping as magic fairy dust without understanding what it does. Don't do that - it's dangerous!)
XSLT 2 can subtract two dates if they are in ISO format simply as
xs:date(d1) - xs:date(d2)
The result is an xs:duration which can be converted to number of days by doing
(xs:date(d1) - xs:date(d2)) div xs:duration('PT1D')
XSLT 1 doesn't have any facilities for date arithmetic, you need an extension library such as the EXSLT date library if available for your chosen processor.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
|
|

March 20th, 2017, 11:01 AM
|
|
Authorized User
|
|
Join Date: Feb 2017
Posts: 21
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Unfortunately I could not. I do not have much information. Could you make an example from the codes I sent? Thank you..
Quote:
Originally Posted by mhkay
Not sure why you are disabling output escaping for a date? Surely a date will never contain any characters that need to be escaped anyway. (Some people use disable-output-escaping as magic fairy dust without understanding what it does. Don't do that - it's dangerous!)
XSLT 2 can subtract two dates if they are in ISO format simply as
xs:date(d1) - xs:date(d2)
The result is an xs:duration which can be converted to number of days by doing
(xs:date(d1) - xs:date(d2)) div xs:duration('PT1D')
XSLT 1 doesn't have any facilities for date arithmetic, you need an extension library such as the EXSLT date library if available for your chosen processor.
|
|
|

March 22nd, 2017, 02:33 AM
|
|
Authorized User
|
|
Join Date: Feb 2017
Posts: 21
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Hello I wrote it like below but it gives an error. Is this a correct spelling?
<xsl:value-of select="(xs:date('2012-12-20')-xs:date('2012-12-10')) div xs:duration('PT1D')"/>
<xsl:value-of select="(xs:date('2012-12-20')-xs:date('2012-12-10')) div xs:dayTimeDuration(P18D)"/>
This is the mistake he gives in all ..
"XalanXPathException: The function number 'http://www.w3.org/2001/XMLSchema:date' is not available...."
|
|

March 22nd, 2017, 02:35 AM
|
|
Authorized User
|
|
Join Date: Feb 2017
Posts: 21
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Hello I wrote it like below but it gives an error. Is this a correct spelling?
<xsl:value-of select="(xs:date('2012-12-20')-xs:date('2012-12-10')) div xs:duration('PT1D')"/>
<xsl:value-of select="(xs:date('2012-12-20')-xs:date('2012-12-10')) div xs:dayTimeDuration(P18D)"/>
This is the mistake he gives in all ..
"XalanXPathException: The function number 'http://www.w3.org/2001/XMLSchema:date' is not available...."
|
|

March 22nd, 2017, 03:15 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
Xalan only supports XSLT and XPath 1.0 so you need to use Saxon 9 or another XSLT 2.0 processor to use the suggestions made so far.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
|
|

March 22nd, 2017, 03:20 AM
|
|
Authorized User
|
|
Join Date: Feb 2017
Posts: 21
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
My xml version="1.0" and ubl 2.1
|
|

March 22nd, 2017, 04:49 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
I made it pretty clear in my answer that you need XSLT 2.0 for this.
XSLT 2.0 means version 2.0 of XSLT. It's nothing to do with the version of XML or the version of UBL.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
|
|

March 22nd, 2017, 04:54 AM
|
|
Authorized User
|
|
Join Date: Feb 2017
Posts: 21
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
My XSLT version 2.0
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
Why is still the same error
|
|

March 22nd, 2017, 05:00 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
Labelling your stylesheet as version 2.0 doesn't suddenly make Xalan into an XSLT 2.0 processor. You need an XSLT processor that understands XSLT 2.0, such as Saxon.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
|
Similar Threads
|
| Thread |
Thread Starter |
Forum |
Replies |
Last Post |
| dates again |
dhoward |
VB.NET 2002/2003 Basics |
12 |
August 22nd, 2007 09:48 AM |
| dates |
DARSIN |
General .NET |
4 |
January 14th, 2005 09:09 AM |
| between dates |
capitala |
Access VBA |
1 |
May 30th, 2004 05:20 PM |
| Dates |
treadmill |
SQL Language |
3 |
July 3rd, 2003 02:32 PM |
| Dates |
oathamm |
Servlets |
1 |
June 27th, 2003 05:43 AM |
|
 |