[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

XPath expression to extract the hour offset from strin

Subject: XPath expression to extract the hour offset from strings that express time offset from UTC?
From: "Roger L Costello costello@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 13 Dec 2022 13:49:16 -0000
 XPath expression to extract the hour offset from strin
Hi Folks,

I have strings that express time offset from UTC. Here are representative
examples:

UTC+5
UTC+1(+2DT)
UTC-11
UTC+4:30
UTC+9:30(+10:30DT)

In areas where daylight savings time is observed, the daylight savings time is
the part in parentheses.

Some offsets have both an hour and minute. The minute portion is after the
colon.

I need to extract the hour offset. So for the above examples, I need to
extract:

+5
+1
-11
+4
+9

This XPath expression seems to do the job:

let $time := "UTC+9:30(+10:30DT)" return
    if (contains($time,'(')) then
        let $part := substring-after(substring-before($time,'('),'UTC') return
            if (contains($part,':')) then
                substring-before($part,':')
            else
                $part
    else
        let $part := substring-after($time,'UTC') return
            if (contains($part,':')) then
                substring-before($part,':')
            else
                $part

Is there a better (simpler, shorter) XPath expression for doing this?

/Roger

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.