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

Re: Different Behavior for Regex in XSD and XSLT/XQuer

Subject: Re: Different Behavior for Regex in XSD and XSLT/XQuery
From: "Peter West lists@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 11 Jan 2018 02:20:28 -0000
Re:  Different Behavior for Regex in XSD and XSLT/XQuer
Eliot,

I havenbt played with REs for a long time, so forgive my naivety, but why
the b60bs?

--
Peter West
pbw@xxxxxxxxx <mailto:pbw@xxxxxxxxx>
bBut you have made it a den of robbers.b

> On 11 Jan 2018, at 2:53 am, Eliot Kimber ekimber@xxxxxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>
> Doh! A subtle but should-be-obvious syntax detail.
>
> Thanks,
>
> Eliot
>
> --
> Eliot Kimber
> http://contrext.com
>
>
> o;?On 1/10/18, 10:39 AM, "David Carlisle d.p.carlisle@xxxxxxxxx"
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>
>    On 10 January 2018 at 16:15, Eliot Kimber ekimber@xxxxxxxxxxxx
>    <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> 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>o;?
>>
>> 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

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.