[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: How to split an RegEx into several lines for read
Dimitre Novatchev wrote:
And you don't need to, as you can see above :) Btw, many languages define an object or type Regex, which is something like a precompiled regular expression. Unfortunately, the W3 committee never created something like xs:regex, which keeps us from defining precompiled regexes. If I understood Michael's comment correctly, the optimizer may or may not 'see' that the regular expression is static or dynamic. If it decides that it is dynamic, the method above will introduce quite a performance hit as Saxon will recompile the regex on each use. If only I were capable of having an input XML document with elements of type xs:regex, the parser could (then) precompile and reuse them (but now I'm drifting...).
Well, you should have a look at my code ;) We do a lot of text-to-xml transform and complex regular expressions help us a lot, but are notoriously hard to read. Hence, about a year ago, I asked about the same question, and I summarized the cumulative answers here: http://www.biglist.com/lists/xsl-list/archives/200607/msg00733.html Other ideas that came up by several people included: * use a custom function that takes a string, removes your self-defined comments and returns a valid regex (there's another thread where I offered a regex-test by a regex, which may come in useful) * use the AVT possibilities to introduce XPath comments: regex=".*{''(: comment here :)}[abc]" or regex=".*{()(: comment here :)}[abc]" * various ways of concat/join plus interspersed XPath comments Also, in that thread, Michael explained why there wasn't a similar construct as the '#' comment in Perl regexes. In practice, in AVTs, I found the xsl:variable approach extremely useful not only for its ease of verbosity, but also because it reliefs me from doubling { and } characters, and escaping (mixed) quotes. Cheers, -- Abel Braaksma
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|