Subject: Re: [xsl] XPath expression to extract the hour offset from strings that express time offset from UTC? From: "David Carlisle d.p.carlisle@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Tue, 13 Dec 2022 14:48:52 -0000 |
<xsl:stylesheet version="2.0" xmlns:xsl=" http://www.w3.org/1999/XSL/Transform"> <xsl:template name="m"> <xsl:sequence select=" ('UTC+5','UTC+1(+2DT)','UTC-11','UTC+4:30','UTC+9:30(+10:30DT)')! replace(.,'UTC([+-][0-9]+).*','$1') "/> </xsl:template> </xsl:stylesheet> produces +5 +1 -11 +4 +9 David On Tue, 13 Dec 2022 at 13:49, Roger L Costello costello@xxxxxxxxx < xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote: > 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] XPath expression to extra, Graydon graydon@xxxx | Thread | Re: [xsl] XPath expression to extra, Dimitre Novatchev dn |
Re: [xsl] XPath expression to extra, Graydon graydon@xxxx | Date | Re: [xsl] XPath expression to extra, Dimitre Novatchev dn |
Month |