[prev in list] [next in list] [prev in thread] [next in thread]
List: xsl-list
Subject: Re: [xsl] Different Behavior for Regex in XSD and XSLT/XQuery
From: "=?UTF-8?B?4peYRHN0YXJQcm9kdWN0aW9uc+KXmCDil5hPZmljaWFsUGFnZeKXmCBmcmVlZGE=?==?U
Date: 2018-01-11 16:31:08
Message-ID: 20180111113025.40986 () lists ! mulberrytech ! com
[Download RAW message or body]
wat is dit alles❓
________________________________
Van: Eliot Kimber ekimber@contrext.com <xsl-list-service@lists.mulberrytech.com>
Verzonden: donderdag 11 januari 2018 08:24:41
Aan: xsl-list@lists.mulberrytech.com
Onderwerp: Re: [xsl] Different Behavior for Regex in XSD and XSLT/XQuery
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@pbw.id.au" <xsl-list-service@lists.mulberrytech.com>
Reply-To: <xsl-list@lists.mulberrytech.com>
Date: Wednesday, January 10, 2018 at 8:20 PM
To: <xsl-list@lists.mulberrytech.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@pbw.id.au<mailto:pbw@pbw.id.au>
"But you have made it a den of robbers."
On 11 Jan 2018, at 2:53 am, Eliot Kimber \
ekimber@contrext.com<mailto:ekimber@contrext.com> \
<xsl-list-service@lists.mulberrytech.com<mailto:xsl-list-service@lists.mulberrytech.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.p.carlisle@gmail.com" \
<xsl-list-service@lists.mulberrytech.com> wrote:
On 10 January 2018 at 16:15, Eliot Kimber ekimber@contrext.com
<xsl-list-service@lists.mulberrytech.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<http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe<-list/1278982> (by email)
XSL-List info and archive<http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe<-list/3010585> (by email<>)
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/651070
or by email: xsl-list-unsub@lists.mulberrytech.com
--~--
[Attachment #3 (text/html)]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} \
--></style> </head>
<body dir="ltr">
<div id="divtagdefaultwrapper" \
style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" \
dir="ltr"> <p style="margin-top:0;margin-bottom:0"><font style="vertical-align: \
inherit;"><font style="vertical-align: inherit;">wat is dit \
alles<span>❓</span></font></font></p> <p style="margin-top:0;margin-bottom:0"><br>
</p>
</div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" \
style="font-size:11pt" color="#000000"><b>Van:</b> Eliot Kimber ekimber@contrext.com \
<xsl-list-service@lists.mulberrytech.com><br> <b>Verzonden:</b> donderdag 11 \
januari 2018 08:24:41<br> <b>Aan:</b> xsl-list@lists.mulberrytech.com<br>
<b>Onderwerp:</b> Re: [xsl] Different Behavior for Regex in XSD and \
XSLT/XQuery</font> <div> </div>
</div>
<style>
<!--
@font-face
{font-family:"Cambria Math"}
@font-face
{font-family:Calibri}
p.x_MsoNormal, li.x_MsoNormal, div.x_MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif}
a:x_link, span.x_MsoHyperlink
{color:blue;
text-decoration:underline}
a:x_visited, span.x_MsoHyperlinkFollowed
{color:purple;
text-decoration:underline}
p.x_msonormal0, li.x_msonormal0, div.x_msonormal0
{margin-right:0in;
margin-left:0in;
font-size:11.0pt;
font-family:"Calibri",sans-serif}
span.x_EmailStyle18
{font-family:"Calibri",sans-serif;
color:windowtext}
.x_MsoChpDefault
{font-size:10.0pt}
@page WordSection1
{margin:1.0in 1.0in 1.0in 1.0in}
div.x_WordSection1
{}
-->
</style>
<div lang="EN-US" link="blue" vlink="purple">
<div class="x_WordSection1">
<p class="x_MsoNormal">So that 05:60 is valid and 05:61 is not. Thus [0-5]\d|60. </p>
<p class="x_MsoNormal"> </p>
<p class="x_MsoNormal">For my application I don't think leap seconds are a \
concern.</p> <p class="x_MsoNormal"> </p>
<p class="x_MsoNormal">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.</p> <p class="x_MsoNormal"> </p>
<p class="x_MsoNormal">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.</p> <p class="x_MsoNormal"> </p>
<p class="x_MsoNormal">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.</p>
<p class="x_MsoNormal"> </p>
<p class="x_MsoNormal">Cheers,</p>
<p class="x_MsoNormal"> </p>
<p class="x_MsoNormal">E.</p>
<div>
<div>
<div>
<p class="x_MsoNormal"><span style="font-size:10.5pt; color:black">--</span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:10.5pt; color:black">Eliot \
Kimber</span></p> </div>
<div>
<p class="x_MsoNormal"><span style="font-size:10.5pt; \
color:black">http://contrext.com</span></p> </div>
<div>
<p class="x_MsoNormal"><span style="font-size:10.5pt; color:black"> </span></p>
</div>
</div>
</div>
<p class="x_MsoNormal"> </p>
<div style="border:none; border-top:solid #B5C4DF 1.0pt; padding:3.0pt 0in 0in 0in">
<p class="x_MsoNormal"><b><span style="font-size:12.0pt; color:black">From: </span>
</b><span style="font-size:12.0pt; color:black">"Peter West \
lists@pbw.id.au" <xsl-list-service@lists.mulberrytech.com><br> \
<b>Reply-To: </b><xsl-list@lists.mulberrytech.com><br> <b>Date: </b>Wednesday, \
January 10, 2018 at 8:20 PM<br> <b>To: \
</b><xsl-list@lists.mulberrytech.com><br> <b>Subject: </b>Re: [xsl] Different \
Behavior for Regex in XSD and XSLT/XQuery</span></p> </div>
<div>
<p class="x_MsoNormal"> </p>
</div>
<p class="x_MsoNormal"><a name="x__MailOriginalBody">Eliot,</a></p>
<div>
<p class="x_MsoNormal"><span style=""> </span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="">I haven't played with REs for a long time, so \
forgive my naivety, but why the "60"s?</span></p> </div>
<div>
<p class="x_MsoNormal"><span style=""> </span></p>
</div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<p class="x_MsoNormal"><span style=""><span style="color:black">--</span></span></p>
</div>
<div>
<p class="x_MsoNormal"><span style=""><span style="color:black">Peter \
West</span></span></p> </div>
<div>
<p class="x_MsoNormal"><span style=""></span><a href="mailto:pbw@pbw.id.au"><span \
style="">pbw@pbw.id.au</span><span style=""></span></a><span style=""><span \
style="color:black"></span></span></p> </div>
<div>
<p class="x_MsoNormal"><span style=""><span style="font-size:8.5pt; \
font-family:"Courier New"">"But you have made it a den of \
robbers."</span></span><span style=""></span></p> </div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<p class="x_MsoNormal"><span style=""> </span></p>
<div>
<blockquote style="margin-top:5.0pt; margin-bottom:5.0pt">
<div>
<p class="x_MsoNormal"><span style="">On 11 Jan 2018, at 2:53 am, Eliot Kimber \
</span> <a href="mailto:ekimber@contrext.com"><span \
style="">ekimber@contrext.com</span><span style=""></span></a><span style=""> \
<</span><a href="mailto:xsl-list-service@lists.mulberrytech.com"><span \
style="">xsl-list-service@lists.mulberrytech.com</span><span \
style=""></span></a><span style="">> wrote:</span></p>
</div>
<p class="x_MsoNormal"><span style=""> </span></p>
<div>
<div>
<p class="x_MsoNormal"><span style="">Doh! A subtle but should-be-obvious syntax \
detail.<br> <br>
Thanks,<br>
<br>
Eliot<br>
<br>
--<br>
Eliot Kimber<br>
</span><a href="http://contrext.com"><span style="">http://contrext.com</span><span \
style=""></span></a><span style=""><br> <br>
<br>
On 1/10/18, 10:39 AM, "David Carlisle d.p.carlisle@gmail.com" \
<xsl-list-service@lists.mulberrytech.com> wrote:<br> <br>
On 10 January 2018 at 16:15, Eliot Kimber ekimber@contrext.com<br>
<xsl-list-service@lists.mulberrytech.com> wrote:<br>
<br>
</span></p>
<blockquote style="margin-top:5.0pt; margin-bottom:5.0pt">
<p class="x_MsoNormal" style="margin-bottom:12.0pt"><span style="">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:<br> <br>
<xs:simpleType name="timestr"><br>
<xs:restriction base="xs:string"><br>
<xs:pattern \
value="(\d|0\d|1\d|2[0123])(:([0-5]\d|60)(:([0-5]\d|60))?)?|24(:00(:00)?)?"/><br>
</xs:restriction><br>
</xs:simpleType><br>
<br>
And it correctly rejects "05:96" as invalid.<br>
<br>
However, using the same regex with start/end anchors added in matches() it does not \
reject "05:96".<br> <br>
This transform:<br>
<br>
<xsl:template match="/"><br>
<xsl:variable name="timestr" \
as="xs:string"<br> \
select="'05:96'"<br> \
/><br> <xsl:variable \
name="is-valid" as="xs:boolean"<br> \
select="matches($timestr, \
'^(\d|0\d|1\d|2[0123])(:([0-5]\d|60)(:([0-5]\d|60))?)?|24(:00(:00)?)?$')"<br> \
/><br> <result><br>
<is-valid><xsl:value-of \
select="$timestr"/>, <xsl:value-of \
select="$is-valid"/></is-valid><br> \
</result><br> </xsl:template><br>
<br>
Produces:<br>
<br>
<result><is-valid>05:96, true</is-valid></result><br>
<br>
From Saxon 9.7. MarkLogic 9 XQuery gives the same result.<br>
<br>
My question: why am I not getting the same behavior from the XSD validator and XPath \
processors for this regular expression?<br> <br>
Thanks,<br>
<br>
Eliot<br>
<br>
--Eliot Kimber<br>
http://contrext.com<br>
<br>
</span></p>
</blockquote>
<p class="x_MsoNormal" style="margin-bottom:12.0pt"><span style=""><br>
you want<br>
<br>
matches($timestr,<br>
'^((\d|0\d|1\d|2[0123])(:([0-5]\d|60)(:([0-5]\d|60))?)?|24(:00(:00)?)?)$')"<br>
<br>
as otherwise the $ only applies to one of the | choices.<br>
<br>
David<br>
<br>
<br>
<br>
</span></p>
</div>
</div>
</blockquote>
</div>
<p class="x_MsoNormal"><span style=""> </span></p>
</div>
<div>
<div style="border:none; border-top:solid black 1.0pt; padding:4.0pt 0in 0in 0in; \
margin-top:5.0pt; margin-bottom:5.0pt"> <p class="x_MsoNormal" align="center" \
style="text-align:center; background:#DDDDDD"> <span style=""></span><a \
href="http://www.mulberrytech.com/xsl/xsl-list"><span style=""><span \
style="font-size:7.5pt; font-family:"Arial",sans-serif">XSL-List info and \
archive</span></span><span style=""></span></a><span style=""><span \
style="font-size:7.5pt; font-family:"Arial",sans-serif; color:#888888"> \
</span></span></p> <p class="x_MsoNormal" align="center" style="text-align:center; \
background:#DDDDDD"> <span style=""></span><a href="-list/1278982"><span \
style=""><span style="font-size:7.5pt; \
font-family:"Arial",sans-serif">EasyUnsubscribe</span></span><span \
style=""></span></a><span style=""><span style="font-size:7.5pt; \
font-family:"Arial",sans-serif; color:#888888"> (</span></span><a \
href=""><span style=""><span style="font-size:7.5pt; \
font-family:"Arial",sans-serif">by email</span></span><span \
style=""></span></a><span style=""><span style="font-size:7.5pt; \
font-family:"Arial",sans-serif; color:#888888">) </span></span></p>
</div>
</div>
</div>
<div>
<div style="border-top:1px solid black; background-color:#dddddd; color:#888888; \
font-size:smaller; padding:5px; text-align:center; \
font-family:arial,verdana,arial,sans-serif; margin-top:1em; clear:both; margin:auto"> \
<a href="http://www.mulberrytech.com/xsl/xsl-list">XSL-List info and archive</a> <div \
style="text-align:center"><a href="-list/3010585" \
style="color:blue">EasyUnsubscribe</a> (<a href="" style="color:blue">by email</a>) \
</div> </div>
</div>
</div>
</body>
</html>
<div><!-- begin bl.html.trailer -->
<div style="border-top:1px solid black; background-color: #dddddd;
color: #888888; font-size: smaller; padding: 5px; text-align: center;
font-family: arial,verdana,arial,sans-serif; margin-top:1em; clear:
both; margin: auto">
<a href="http://www.mulberrytech.com/xsl/xsl-list">
XSL-List info and archive</a>
<div style="text-align:center;">
<a style="color: blue;"
href="http://lists.mulberrytech.com/unsub/xsl-list/651070"
> EasyUnsubscribe</a>
(<a style="color: blue;"
href="mailto:xsl-list-unsub@lists.mulberrytech.com?subject=remove"
> by email</a>)
</div>
</div>
<!-- end bl.html.trailer --></div>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic