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

Re: analyze-string regex

Subject: Re: analyze-string regex
From: John Lumley <john@xxxxxxxxxxxx>
Date: Fri, 28 Mar 2014 10:29:36 +0000
Re:  analyze-string regex
On 28/03/2014 10:15, Michael Kay wrote:
However, another approach I have seen is to build the regular expression methodically, for example with a sequence of variables:

<xsl:variable name="number">\d+</xsl:variable>
<xsl:variable name="string">"[^"]*"</xsl:variable>
<xsl:vairable name="number-or-string" select="{$number}|{$string}"/>
another advantage of this technique, when using <xsl:analyze-string> is that you can reuse the definitions within a choose inside matching-substring, e.g.

<xsl:analyze-string select="." regex="{$number-or-string}">
    <xsl:matching-substring>
        <xsl:choose>
           <xsl:when test="matches(.,$number)">......
           <xsl:when test="matches(.,$string)">......

and of course the cases are only defined once - and usually in 'plain text' situations. However group numbering can still be an issue. If you're doing a lot of that then some simple preprocessing could assist - collecting the sub-regexes from the tests and forming up the variables etc....

--
*John Lumley* MA PhD CEng FIEE
john@xxxxxxxxxxxx <mailto:john@xxxxxxxxxxxx>
on behalf of Saxonica Ltd

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.