Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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
 
Old November 30th, 2007, 02:24 PM
Authorized User
 
Join Date: Jun 2007
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:
matches($hour,(1[0-9]|2[0-9])

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"
                select="format-dateTime($increase,'[h]')"/>
  <xsl:value-of select="if (matches($hour,(1[0-9]|2[0-9]))
                           then $hour
                           else substring($hour,1,1) "/>
</xsl:function>
 
Old November 30th, 2007, 03:47 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

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 -/
 
Old December 1st, 2007, 06:55 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

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)





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





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