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

RE: Another tokenize() question

Subject: RE: Another tokenize() question
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Wed, 11 Aug 2004 12:12:15 +0100
regex quantifiers
> On Wed, 11 Aug 2004, David Carlisle wrote:
> 
> > regex="(\w|{{[^{{}}]*}})+"
> 
> Now I know I'm being a pain, but when I use that I get:
> 
> saxon -o temp2.xml temp.xml addwords2.xsl Error at 
> analyze-string on line 29 of
> file:addwords2.xsl: 
> net.sf.saxon.type.RegexTranslator$RegexSyntaxException: Error at
>   character 4 in regular expression: expected ())
>     Transformation failed: Run-time errors were reported
> 

Ignoring the AVT rules, the regex syntax allows { to be used without
escaping inside [], but not outside: outside [] it is reserved for use in
regex quantifiers such as x{3}. So it must be escaped as \{. So the regular
expression you want is

(\w|\{[^{}]*\})+

which is written in the regex attribute as

regex="(\w|\{{[^{{}}]*\}})+"

It might be less painful to do:

<xsl:variable name="regex">(\w|\{[^{}]*\})+</xsl:variable>
<xsl:analyze-string regex="{$regex}">

though sadly, I suspect that will prevent Saxon precompiling the regular
expression :-(

Better idea: use chevrons instead of curlies.

Michael Kay

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.