Wrox Programmer Forums
|
BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition ISBN: 978-0-470-19274-0
This is the forum to discuss the Wrox book XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition by Michael Kay; ISBN: 9780470192740
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition ISBN: 978-0-470-19274-0 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
 
Old August 25th, 2011, 06:15 PM
Authorized User
 
Join Date: Jul 2009
Posts: 23
Thanks: 5
Thanked 0 Times in 0 Posts
Default Computing date/day patterns

Hi,

Given a set of dates in XML format (see below for sample XML), I need to compute the following information:

- what day of the month it is, e.g. 1st, 2nd, .. , nth, last (this is an easy one)
- the nth weekday of the month it corresponds to, e.g. 1st Monday, 2nd Wednesday, last Friday
- the nth month that it belongs to amongst the months involved in the set of dates, e.g. given dates from August 25 to October 15, September 5th would have n = 2

Here's a sample XML node:

Code:
<period date="12/6/2011" day="Tue" month="Dec" year="2011">
Are there any functions in XSLT that would provide this type of info or make this task easier to implement?

Thanks!
 
Old August 25th, 2011, 07:42 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

First convert the date to ISO format YYYY-MM-DD, using regex functions or simply substring-before/after. Then you can convert to xs:date(), and then you have a wide range of functions and operators available, for example subtracting two dates to get a dateTimeDuration. Also look at format-date() which has some extra capabilities like getting the ISO week number (week within year) or the week-within-month.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following User Says Thank You to mhkay For This Useful Post:
baseliner (September 14th, 2011)
 
Old September 14th, 2011, 07:33 PM
Authorized User
 
Join Date: Jul 2009
Posts: 23
Thanks: 5
Thanked 0 Times in 0 Posts
Default

Thanks Michael for pointing me to that function.. I was able to do most of what I needed. Appreciate the help.





Similar Threads
Thread Thread Starter Forum Replies Last Post
subtracting 1 day from the current date Jeff C# 2 March 12th, 2009 01:16 AM
make date display go back a day crmpicco Javascript How-To 2 March 16th, 2006 01:42 PM
how to get the day from a given date pherms Classic ASP Basics 2 April 16th, 2004 05:38 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.