Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old March 20th, 2017, 09:15 AM
Authorized User
Points: 60, Level: 1
Points: 60, Level: 1 Points: 60, Level: 1 Points: 60, Level: 1
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Feb 2017
Posts: 16
Thanks: 1
Thanked 0 Times in 0 Posts
Default 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..
Reply With Quote
  #2 (permalink)  
Old March 20th, 2017, 09:23 AM
mhkay's Avatar
Wrox Author
Points: 18,173, Level: 58
Points: 18,173, Level: 58 Points: 18,173, Level: 58 Points: 18,173, Level: 58
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,919
Thanks: 0
Thanked 277 Times in 272 Posts
Default

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
Reply With Quote
  #3 (permalink)  
Old March 20th, 2017, 11:01 AM
Authorized User
Points: 60, Level: 1
Points: 60, Level: 1 Points: 60, Level: 1 Points: 60, Level: 1
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Feb 2017
Posts: 16
Thanks: 1
Thanked 0 Times in 0 Posts
Default

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 View Post
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.
Reply With Quote
  #4 (permalink)  
Old March 22nd, 2017, 02:33 AM
Authorized User
Points: 60, Level: 1
Points: 60, Level: 1 Points: 60, Level: 1 Points: 60, Level: 1
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Feb 2017
Posts: 16
Thanks: 1
Thanked 0 Times in 0 Posts
Default

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...."
Reply With Quote
  #5 (permalink)  
Old March 22nd, 2017, 02:35 AM
Authorized User
Points: 60, Level: 1
Points: 60, Level: 1 Points: 60, Level: 1 Points: 60, Level: 1
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Feb 2017
Posts: 16
Thanks: 1
Thanked 0 Times in 0 Posts
Default

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...."
Reply With Quote
  #6 (permalink)  
Old March 22nd, 2017, 03:15 AM
Friend of Wrox
Points: 6,516, Level: 34
Points: 6,516, Level: 34 Points: 6,516, Level: 34 Points: 6,516, Level: 34
Activity: 50%
Activity: 50% Activity: 50% Activity: 50%
 
Join Date: Nov 2007
Location: Germany
Posts: 1,218
Thanks: 0
Thanked 237 Times in 236 Posts
Default

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
Reply With Quote
  #7 (permalink)  
Old March 22nd, 2017, 03:20 AM
Authorized User
Points: 60, Level: 1
Points: 60, Level: 1 Points: 60, Level: 1 Points: 60, Level: 1
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Feb 2017
Posts: 16
Thanks: 1
Thanked 0 Times in 0 Posts
Default

My xml version="1.0" and ubl 2.1
Reply With Quote
  #8 (permalink)  
Old March 22nd, 2017, 04:49 AM
mhkay's Avatar
Wrox Author
Points: 18,173, Level: 58
Points: 18,173, Level: 58 Points: 18,173, Level: 58 Points: 18,173, Level: 58
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,919
Thanks: 0
Thanked 277 Times in 272 Posts
Default

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
Reply With Quote
  #9 (permalink)  
Old March 22nd, 2017, 04:54 AM
Authorized User
Points: 60, Level: 1
Points: 60, Level: 1 Points: 60, Level: 1 Points: 60, Level: 1
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Feb 2017
Posts: 16
Thanks: 1
Thanked 0 Times in 0 Posts
Default

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
Reply With Quote
  #10 (permalink)  
Old March 22nd, 2017, 05:00 AM
mhkay's Avatar
Wrox Author
Points: 18,173, Level: 58
Points: 18,173, Level: 58 Points: 18,173, Level: 58 Points: 18,173, Level: 58
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,919
Thanks: 0
Thanked 277 Times in 272 Posts
Default

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
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 08: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



All times are GMT -4. The time now is 10:39 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.