|
Subject: Re: [xsl] XPath expression to extract the hour offset from strings that express time offset from UTC? From: "Dimitre Novatchev dnovatchev@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Wed, 14 Dec 2022 01:23:55 -0000 |
On Tue, Dec 13, 2022 at 4:59 PM Terry Badger terry_badger@xxxxxxxxx <
xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
> How about this
> <xsl:value-of select="substring(., 4, 2)"/>
> <xsl:value-of select="translate(substring(., 6, 1), '1234567890:(',
> '1234567890')"/>
> TerryBadger
>
>
The above is equivalent to this Xpath expression:
concat(substring($t, 4, 2), translate(substring($t, 6, 1), '1234567890:(',
'1234567890'))
It is one character longer than the one I proposed:
substring(substring-before(concat(substring-before(concat($t, ":"), ":"),
"("), "("), 4)
Here are the two one under the other (but to see the true difference in
length one must use a fixed font:
concat(substring($t, 4, 2), translate(substring($t, 6, 1), '1234567890:(',
'1234567890'))
substring(substring-before(concat(substring-before(concat($t, ":"), ":"),
"("), "("), 4)
Thanks,
Dimitre
>
>
>
>
>
> On Tuesday, December 13, 2022 at 10:22:09 AM EST, Dimitre Novatchev
> dnovatchev@xxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>
>
>
>
>
> Here is a pure XPath 1.0 solution:
>
> substring(substring-before(concat(substring-before(concat($t, ":"), ":"),
> "("), "("), 4)
>
> And this expression:
>
> for $t in ("UTC+5", "UTC+1(+2DT)", "UTC-11", "UTC+4:30",
> "UTC+9:30(+10:30DT)")
> return
> substring(substring-before(concat(substring-before(concat($t, ":"),
> ":"), "("), "("), 4)
>
> evaluates exactly to the wanted result-sequence:
>
> +5
> +1
> -11
> +4
> +9
>
> https://github.com/dnovatchev/FXSL-XSLT2/blob/master/ExtractingHours.jpg
>
> Thanks,
> Dimitre
>
> On Tue, Dec 13, 2022 at 5:49 AM 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
> >
> >
> >
>
>
>
> XSL-List info and archive
> EasyUnsubscribe (by email)
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] XPath expression to extra, Terry Badger terry_b | Thread | [xsl] looking for a visually clean , Chris Papademetrious |
| Re: [xsl] XPath expression to extra, Terry Badger terry_b | Date | [xsl] looking for a visually clean , Chris Papademetrious |
| Month |