Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 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 Search this Thread Display Modes
  #1 (permalink)  
Old August 25th, 2011, 06:15 PM
Authorized User
Points: 102, Level: 2
Points: 102, Level: 2 Points: 102, Level: 2 Points: 102, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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!
Reply With Quote
  #2 (permalink)  
Old August 25th, 2011, 07:42 PM
mhkay's Avatar
Wrox Author
Points: 18,481, Level: 59
Points: 18,481, Level: 59 Points: 18,481, Level: 59 Points: 18,481, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,960
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
Reply With Quote
The Following User Says Thank You to mhkay For This Useful Post:
baseliner (September 14th, 2011)
  #3 (permalink)  
Old September 14th, 2011, 07:33 PM
Authorized User
Points: 102, Level: 2
Points: 102, Level: 2 Points: 102, Level: 2 Points: 102, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
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



All times are GMT -4. The time now is 07:53 PM.


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