[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 \
&lt;xsl-list-service@lists.mulberrytech.com&gt;<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>&nbsp;</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">&nbsp;</p>
<p class="x_MsoNormal">For my application I don't think leap seconds are a \
concern.</p> <p class="x_MsoNormal">&nbsp;</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">&nbsp;</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">&nbsp;</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">&nbsp;</p>
<p class="x_MsoNormal">Cheers,</p>
<p class="x_MsoNormal">&nbsp;</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">&nbsp;</span></p>
</div>
</div>
</div>
<p class="x_MsoNormal">&nbsp;</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">&quot;Peter West \
lists@pbw.id.au&quot; &lt;xsl-list-service@lists.mulberrytech.com&gt;<br> \
<b>Reply-To: </b>&lt;xsl-list@lists.mulberrytech.com&gt;<br> <b>Date: </b>Wednesday, \
January 10, 2018 at 8:20 PM<br> <b>To: \
</b>&lt;xsl-list@lists.mulberrytech.com&gt;<br> <b>Subject: </b>Re: [xsl] Different \
Behavior for Regex in XSD and XSLT/XQuery</span></p> </div>
<div>
<p class="x_MsoNormal">&nbsp;</p>
</div>
<p class="x_MsoNormal"><a name="x__MailOriginalBody">Eliot,</a></p>
<div>
<p class="x_MsoNormal"><span style="">&nbsp;</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="">&nbsp;</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:&quot;Courier New&quot;">"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="">&nbsp;</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=""> \
&lt;</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="">&gt;  wrote:</span></p>
</div>
<p class="x_MsoNormal"><span style="">&nbsp;</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, &quot;David Carlisle d.p.carlisle@gmail.com&quot; \
&lt;xsl-list-service@lists.mulberrytech.com&gt; wrote:<br> <br>
&nbsp;&nbsp;&nbsp;On 10 January 2018 at 16:15, Eliot Kimber ekimber@contrext.com<br>
&nbsp;&nbsp;&nbsp;&lt;xsl-list-service@lists.mulberrytech.com&gt; 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>
&nbsp;&lt;xs:simpleType name=&quot;timestr&quot;&gt;<br>
&nbsp;&nbsp;&nbsp;&lt;xs:restriction base=&quot;xs:string&quot;&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;xs:pattern \
value=&quot;(\d|0\d|1\d|2[0123])(:([0-5]\d|60)(:([0-5]\d|60))?)?|24(:00(:00)?)?&quot;/&gt;<br>
 &nbsp;&nbsp;&nbsp;&lt;/xs:restriction&gt;<br>
&nbsp;&lt;/xs:simpleType&gt;<br>
<br>
And it correctly rejects &quot;05:96&quot; as invalid.<br>
<br>
However, using the same regex with start/end anchors added in matches() it does not \
reject &quot;05:96&quot;.<br> <br>
This transform:<br>
<br>
&nbsp;&lt;xsl:template match=&quot;/&quot;&gt;<br>
&nbsp;&nbsp;&nbsp;&lt;xsl:variable name=&quot;timestr&quot; \
as=&quot;xs:string&quot;<br> \
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;select=&quot;'05:96'&quot;<br> \
&nbsp;&nbsp;&nbsp;/&gt;<br> &nbsp;&nbsp;&nbsp;&lt;xsl:variable \
name=&quot;is-valid&quot; as=&quot;xs:boolean&quot;<br> \
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;select=&quot;matches($timestr, \
'^(\d|0\d|1\d|2[0123])(:([0-5]\d|60)(:([0-5]\d|60))?)?|24(:00(:00)?)?$')&quot;<br> \
&nbsp;&nbsp;&nbsp;/&gt;<br> &nbsp;&nbsp;&nbsp;&lt;result&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;is-valid&gt;&lt;xsl:value-of \
select=&quot;$timestr&quot;/&gt;, &lt;xsl:value-of \
select=&quot;$is-valid&quot;/&gt;&lt;/is-valid&gt;<br> \
&nbsp;&nbsp;&nbsp;&lt;/result&gt;<br> &nbsp;&lt;/xsl:template&gt;<br>
<br>
Produces:<br>
<br>
&lt;result&gt;&lt;is-valid&gt;05:96, true&lt;/is-valid&gt;&lt;/result&gt;<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>
&nbsp;&nbsp;&nbsp;you want<br>
<br>
&nbsp;&nbsp;&nbsp;matches($timestr,<br>
&nbsp;&nbsp;&nbsp;'^((\d|0\d|1\d|2[0123])(:([0-5]\d|60)(:([0-5]\d|60))?)?|24(:00(:00)?)?)$')&quot;<br>
 <br>
&nbsp;&nbsp;&nbsp;as otherwise the $ only applies to one of the | choices.<br>
<br>
&nbsp;&nbsp;&nbsp;David<br>
<br>
<br>
<br>
</span></p>
</div>
</div>
</blockquote>
</div>
<p class="x_MsoNormal"><span style="">&nbsp;</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:&quot;Arial&quot;,sans-serif">XSL-List info and \
archive</span></span><span style=""></span></a><span style=""><span \
style="font-size:7.5pt; font-family:&quot;Arial&quot;,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:&quot;Arial&quot;,sans-serif">EasyUnsubscribe</span></span><span \
style=""></span></a><span style=""><span style="font-size:7.5pt; \
font-family:&quot;Arial&quot;,sans-serif; color:#888888">  (</span></span><a \
href=""><span style=""><span style="font-size:7.5pt; \
font-family:&quot;Arial&quot;,sans-serif">by email</span></span><span \
style=""></span></a><span style=""><span style="font-size:7.5pt; \
font-family:&quot;Arial&quot;,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