[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: Tue, 8 Jan 2002 18:03:41 +0000
regular expression xd

> <xsl:apply-regexp-templates-to-string select="text()"/>
> ...
> <xsl:regexp-template match="\sqrt{([^{}]*)}">
> <msqrt>
> <xsl:apply-regexp-templates-to-string select="$1"/>
> </msqrt>
> </xsl:regexp-template>
> <xsl:regexp-template match="\gamma">
> <mi>&#947;</mi>
> </xsl:regexp-template>

Ooh, tasty...

Presumably the match patterns would match the entire string? So to do
the whitespace replacement stuff that I mentioned, you'd have:

<xsl:regexp-template match="([^&#xA;&#x9;&#xD;]*)([&#xA;&#x9;&#xD;])(.*)">
  <xsl:value-of select="$1" />
  <xsl:value-of select="if ($2 = '&#xA;') then '\n'
                        else if ($2 = '&#x9;') then '\t'
                        else if ($2 = '&#xD;') then '\r'" />
  <xsl:apply-regexp-templates-to-string select="$3" />

The big weakness if this was the *only* method of doing matches is
that you can't use it with dynamic regular expressions - for example
match strings that contain the keyword $keyword as a word. Any ideas
around that one?

On a kind of related topic, I did wonder whether XSLT 2.0 would
support templates that matched things other than nodes (but it seems
not). It occurred to me that this could be useful if, for example, you
wanted all your numbers to be formatted in the same way throughout the
document - you could have:

<xsl:template match="value of type xs:decimal">
  <xsl:value-of select="format-number(., '#,##0.00')" />

[Note slight adjustment to the syntax for specifying datatypes, to
avoid confusion with element names.]

and then apply templates to whatever values wherever you found them
(even if they were found via substring or in sequences or whatever).

If there were string-regexp templates and not general value-matching
templates, then people might be tempted to use regular expressions to
identify data types in their match patterns instead.



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.