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

Re: Using regular expressions in stylesheet

Subject: Re: Using regular expressions in stylesheet
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Fri, 17 May 2002 10:50:00 +0100
xalan regular expression
Hi Trang,

> I am new to XSLT technology and would like to find out whether the
> latest version of XPath already supports regular expressions (I am
> currently using Xalan for transformations).

No -- XPath 1.0 doesn't support regular expressions. It's something
that's promised in XPath 2.0. You could write an extension function
for Xalan that would use Java's regexp processing, possibly.

> I would like to use regular expressions to extract digits out of a
> string containing alphanumeric characters (for example, extract '5'
> out of '5a'). Can you tell me of an appropriate function that allows
> me to do this in my stylesheet?

It depends on how complex the structure of the string is, but you can
probably do this using the basic string manipulation functions in
XPath 1.0. Specifically, you can remove the non-numeric characters
from a string using:

  translate($string, translate($string, '0123456789', ''), '')

The inner translate() removes the numeric characters from the string,
so that you're left with a string that contains all the non-numeric
characters in the string. The outer translate() then removes all those
characters from the original string, so you're left with only the
numeric characters.

Or you could write a recursive template that goes through the string
one character at a time to extract the numeric characters prior to the
first non-numeric character; as I say, it depends on the structure of
your string.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


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


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.