xsl-list
[Top] [All Lists]

Re: [xsl] analyze-string regex

2014-03-28 05:29:58
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(_at_)saxonica(_dot_)com <mailto:john(_at_)saxonica(_dot_)com>
on behalf of Saxonica Ltd

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>