Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
| 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
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 30th, 2007, 02:24 PM
Authorized User
Join Date: Jun 2007
Location: , , .
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default comparing strings and integers

Given 2007-07-25T01:00:00-06:00

I am trying to increase the time by one hour, and then extract the hour (minus the preceeding '0')

For example,
2007-07-25T01:00:00-06:00 would return 2
2007-07-25T11:00:00-06:00 would return 12

I am receiving an error with the following regex comparison:

Error: Arithmetic operator is not defined for arguments of types (xs:string, xs:integer)

<xsl:function name="ercot:extract-hour">

  <xsl:param name="date" as="xs:dateTime"/>
  <xsl:variable name="increase" select="$date + $one-hour"/>
  <xsl:variable name="hour"
  <xsl:value-of select="if (matches($hour,(1[0-9]|2[0-9]))
                           then $hour
                           else substring($hour,1,1) "/>
Reply With Quote
  #2 (permalink)  
Old November 30th, 2007, 03:47 PM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts

Well that might be because the second argument for matches needs to be a string, i.e. enclosed in single quotes.

/- Sam Judson : Wrox Technical Editor -/
Reply With Quote
  #3 (permalink)  
Old December 1st, 2007, 06:55 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts

As you're using XSLT 2.0 why not use the inbuilt functions? Look at creating a new dateTimeDuration of one hour and adding it to your date using the + operator. Then use hours-from-dateTime() to get the hour part.


Joe (Microsoft MVP - XML)
Reply With Quote

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
comparing strings seymour_glass C# 5 February 6th, 2007 04:49 PM
Unsigned integers AndrewH Java Basics 1 September 26th, 2006 02:46 PM
Comparing two strings shasto100 XSLT 2 April 28th, 2006 08:10 AM
comparing strings treasacrowe Classic ASP Databases 5 September 11th, 2004 09:48 AM
how can i convert strings into integers amahja56 C++ Programming 2 February 27th, 2004 06:27 PM

All times are GMT -4. The time now is 10:07 AM.

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