[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Regular expression functions (Was: Re: comments on
David, > - introducing a syntax for naming the subexpressions rather than > numbering them > > this works surprisingly well in omnimark, although I thought it odd > when I first saw it. It also allows you to grab nested strings > rather than having to reconcatenate #1 #2 etc for example (in a > mixture of omnimark and sed/perl syntax) It does sound really neat - I always get lost about which bracket I'm on in a regular expression! The more I think about it, the less I like the assignment-to-numerically-named-variables idea (which was mine in the first place, I freely admit, but I think I'm allowed to change my mind :) An alternative that feels more XSLT/XPath-like is to have a function that gives you access to the results of the match. It could return a sequence of the matched strings (or positions or whatever), or another idea would be to have the function operate over a sequence of integers, with each integer giving the index of the subexpression from the last. To give you an idea about what I'm going on about, the signature of the function I have in mind is: current-match(integer* $subexpression) => xs:string say you had: <xsl:regexp-template match="(([a-z])([a-z0-9]*))([?+*]?)"> ... </xsl:regexp-template> (an identifier followed by an optional occurrence indicator). Within the regexp-template you could use a current-match() function to give you the results of the match. Say the overall matched string was: "foo?" Then the valid calls to current-match() (and their results) would be: current-match(1) => "foo" current-match(2) => "?" current-match((1, 1)) => "f" current-match((1, 2)) => "oo" current-match(()) => "foo?" This still involves counting brackets (which isn't easy), but at least you won't usually have to count very many of them! Cheers, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
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
|