Subject: RE: Q - Parsing & Manipulating Strings from XSL
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Mon, 30 May 2005 10:13:07 +0100
|
> I have another question: Another number is returned as type string.
> This represents time in minutes. For e.g for '315', I want to do is
> format it as 5 hrs 15 mins.
>
> The formula is:
>
> mins = ( (315 mod 60) div 100 ) * 60
> hrs = 315 - (315 mod 60)
>
> How can I do this in Xquery ? This data is returned in a
> <JrnyTm></JrnyTm> tag.
>
(Your previous question asked for an XSLT solution, you're now asking for
XQuery. In principle XQuery is off-topic for this list, but in practice, you
can use the same approach in both. But the decimal-format/format-number
solution I gave you earlier is XSLT-only)
You've got a choice between using numeric arithmetic or duration arithmetic.
It's probably cleanest to use duration arithmetic though it's a bit verbose.
declare variable $one-minute := xdt:dayTimeDuration('PT1M')
then
let $time := xs:integer(JrnyTm) * $one-minute,
$hours := hours-from-duration($time),
$minutes := minutes-from-duration($time)
return
concat($hours, ' hrs ', $minutes, ' minutes ')
Michael Kay
http://www.saxonica.com/
| Current Thread |
Dimitre Novatchev - 29 May 2005 20:01:15 -0000
- Ahsan Ali - 30 May 2005 04:29:59 -0000
- Michael Kay - 30 May 2005 09:13:28 -0000 <=
- Message not available
- Ahsan Ali - 30 May 2005 13:53:35 -0000
- Michael Kay - 30 May 2005 16:11:30 -0000
- Message not available
- Karl Stubsjoen - 30 May 2005 17:05:03 -0000
- Message not available
- Ahsan Ali - 31 May 2005 06:29:29 -0000
|
|