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

Re: Need an XPath expression which returns all xs:patt

Subject: Re: Need an XPath expression which returns all xs:pattern elements containing a regex that permits an unbounded number of characters
From: "Dimitre Novatchev dnovatchev@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 4 Apr 2024 16:13:41 -0000
Re:  Need an XPath expression which returns all xs:patt
Hi Roger,

In order to deal with '\' used as an escape character, then such a solution
must ignore '\\' as this is not an escape character but represents the
(regular) character `\`.
In the same way, '\\\\' represents 2 (regular) consecutive '\' characters,
..., and so on, ...
And a sequence of odd-number of backslashes should be replaced by a single
backslash character.

A subexpression doing this must precede any further processing.

One such subexpression is:

    replace($input, '(\\\\)+', '')

Then on the result of the above (using the above result as the input) one
can check for a single '\' followed by any wanted strings.



Thanks,
Dimitre

On Thu, Apr 4, 2024 at 5:29b/AM Roger L Costello costello@xxxxxxxxx <
xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

> Hi Folks,
>
> I want to find, in an XML Schema, all xs:pattern elements containing a
> regex that permits an unbounded number of characters.
>
> Here are examples of xs:pattern elements that I want to find:
>
> <xs:pattern value="A*"/>
> <xs:pattern value="A+"/>
> <xs:pattern value="A{0,.}"/>
> <xs:pattern value="A{1,.}"/>
>
> I do not want either of the following xs:pattern elements because -- due
> to the escape symbol -- they do not permit an unbounded number of
> characters:
>
> <xs:pattern value="A\*"/>
> <xs:pattern value="A\+"/>
>
> I created an XPath 2.0 expression to find the desired xs:pattern elements:
>
> xs:pattern[
>         contains(@value, '*') or
>         contains(@value, '+') or
>         contains(@value, '{1,}') or
>         contains(@value, '{0,}')
>     ]
>
> Eek! That is not correct. It incorrectly returns the xs:pattern elements
> with escaped asterisk and escaped plus symbols:
>
> <xs:pattern value="A\*"/>
> <xs:pattern value="A\+"/>
>
> How to fix my XPath expression? Is the solution to add a second predicate:
>
> xs:pattern[
>         contains(@value, '*') or
>         contains(@value, '+') or
>         contains(@value, '{1,}') or
>         contains(@value, '{0,}')
>     ][
>         not(contains(@value, '\*')) and
>         not(contains(@value, '\+'))
>     ]
>
> Is that correct? Is that the best approach? Is there a better approach?
>
> Bonus points if you can answer this question: Is my XPath expression
> catching all xs:pattern elements that have a regex that permits an
> unbounded number of characters?
>
> Note: For reasons that I will not explain, the XPath expression must be an
> XPath 2.0 expression.
>
> /Roger

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.