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

Comments in XPath / XSLT regular expressions?

Subject: Comments in XPath / XSLT regular expressions?
From: Abel Braaksma Online <abel.online@xxxxxxxxx>
Date: Wed, 26 Jul 2006 10:45:14 +0200
xpath comment
Dear List,

The regular expression syntax used in XSLT and XPath is largely based on Perl's regular expression syntax. Perl added a very useful construct to their regular expression dialect: the /x modifier. It gives "whitespace freedom" and allows for comments inside regular expressions. It was a great enhancement at the time, especially for moderate to difficult regexes.

I've been reading through the regex chapter of the XPath 2.0 Programmer's Reference, hoping for something similar, but it wasn't mentioned. I know there's the smiley-comment syntax for XPath, but it does not work inside a regex. Unfortunately, the old, pre-/x time, way seems the only way: dissecting the regex in strings and concatenating it back again. I don't think this is right, or even adds to readability though. Does anybody know of a way to add comments and whitespace to regular expressions? Much like the /x modifier? Or should I add some preparser van normalize-space? That won't be trivial, I think.

This is the best I could think of for the moment (example takes a filepath and gets the filename part out and adds .xml, there are flaws in the reqex, I know ;)

select="replace(., concat('^.*?', (: non-greedy: grab everything :)
'([^/\\]+)', (: the last part of the path: does not contain (back)slashes. Grab it to $1 :)
'\.', (: the dot separating the extension from the filename :)
'[^\.]*$' (: not-a-dot until end of string, this is the extension :)
), '$1.xml')" />


But it ain't very pretty with all them quotes and comma's, ain't it? ;)

Anyone any ideas?

Cheers,
Abel Braaksma
www.nuntia.nl

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.