Re: Using regular expressions in stylesheet
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
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