xsl-list
[Top] [All Lists]

Re: [xsl] Different Behavior for Regex in XSD and XSLT/XQuery

2018-01-11 10:24:41
So that 05:60 is valid and 05:61 is not. Thus [0-5]\d|60. 

 

For my application I don’t think leap seconds are a concern.

 

The use case is users entering the shortest possible value that can be reliably 
interpreted as an xs:time value, e.g. “5” (for 05:00:00), 5:1 (for 05:01:00), 
etc.

 

Since an invalid string passed to xs:time() throws an exception, important to 
validate the value before trying to make a good time string out of it.

 

This is in the context of a configuration document where the user is specifying 
time values that are interpreted dynamically by a long-running process with 
little or no opportunity to report failure to the user who created the 
configuration file.

 

Cheers,

 

E.

--

Eliot Kimber

http://contrext.com

 

 

From: "Peter West lists(_at_)pbw(_dot_)id(_dot_)au" 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com>
Reply-To: <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Date: Wednesday, January 10, 2018 at 8:20 PM
To: <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Subject: Re: [xsl] Different Behavior for Regex in XSD and XSLT/XQuery

 

Eliot,

 

I haven’t played with REs for a long time, so forgive my naivety, but why the 
“60”s?

 

--

Peter West

pbw(_at_)pbw(_dot_)id(_dot_)au

“But you have made it a den of robbers.”

 

On 11 Jan 2018, at 2:53 am, Eliot Kimber ekimber(_at_)contrext(_dot_)com 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

 

Doh! A subtle but should-be-obvious syntax detail.

Thanks,

Eliot

--
Eliot Kimber
http://contrext.com


On 1/10/18, 10:39 AM, "David Carlisle 
d(_dot_)p(_dot_)carlisle(_at_)gmail(_dot_)com" 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

   On 10 January 2018 at 16:15, Eliot Kimber ekimber(_at_)contrext(_dot_)com
   <xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:


I have this simple type in an XSD, which is my attempt to validate strings that 
are subsets of the string representation of xs:time values:

 <xs:simpleType name="timestr">
   <xs:restriction base="xs:string">
     <xs:pattern 
value="(\d|0\d|1\d|2[0123])(:([0-5]\d|60)(:([0-5]\d|60))?)?|24(:00(:00)?)?"/>
   </xs:restriction>
 </xs:simpleType>

And it correctly rejects "05:96" as invalid.

However, using the same regex with start/end anchors added in matches() it does 
not reject "05:96".

This transform:

 <xsl:template match="/">
   <xsl:variable name="timestr" as="xs:string"
     select="'05:96'"
   />
   <xsl:variable name="is-valid" as="xs:boolean"
     select="matches($timestr, 
'^(\d|0\d|1\d|2[0123])(:([0-5]\d|60)(:([0-5]\d|60))?)?|24(:00(:00)?)?$')"
   />
   <result>
     <is-valid><xsl:value-of select="$timestr"/>, <xsl:value-of 
select="$is-valid"/></is-valid>
   </result>
 </xsl:template>

Produces:

<result><is-valid>05:96, true</is-valid></result>

From Saxon 9.7. MarkLogic 9 XQuery gives the same result.

My question: why am I not getting the same behavior from the XSD validator and 
XPath processors for this regular expression?

Thanks,

Eliot

--Eliot Kimber
http://contrext.com



   you want

   matches($timestr,
   '^((\d|0\d|1\d|2[0123])(:([0-5]\d|60)(:([0-5]\d|60))?)?|24(:00(:00)?)?)$')"

   as otherwise the $ only applies to one of the | choices.

   David




 

XSL-List info and archive 

EasyUnsubscribe (by email) 
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--
<Prev in Thread] Current Thread [Next in Thread>