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

Re: Regular expression functions (Was: Re: comments on

Subject: Re: Regular expression functions (Was: Re: comments on December F&O draft)
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Thu, 10 Jan 2002 12:47:53 +0000
counting brackets

>   - 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]*))([?+*]?)">

(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:


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!


Jeni Tennison

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Current Thread


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.
First Name
Last Name
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.