Using regular expressions through XSLT 2.0
How XSLT 2.0 will change your world
XSLT 2.0 is nearing release, and when it arrives and receives substantial processor support, your life will be a lot easier. The MindMap team has been getting a jump on things by looking over the early drafts of the XSLT 2.0 specification (see Resources).
XSLT 2.0 will take the hassle out of quite a few things that the MindMap team has found somewhat frustrating with XSLT 1.0, particularly string management. XSLT 2.0 provides support for regular expressions, which are a pattern-based method of searching for specific strings of text found in other languages with powerful string manipulation capabilities like Perl.
However, you shouldn't use XSLT 2.0 in a production environment quite yet. It's hard to say when the specification will be finalized, and it could still change substantially. The current working draft is in Last Call, which means this is the last opportunity for public comment, but this has been a slow-moving specification, so final delivery might not happen before the second half of 2004. After that, it will take some time for the language to mature and for XSLT processors to work out the bugs (and I expect plenty of them because the architecture of the language experienced some core changes, especially with regards to data typing).
So what do you need to experiment with XSLT 2.0 today? Saxon, an XSLT processor developed by Michael Kay, provides an immediate opportunity for testing basic features of XSLT 2.0 (see Resources for the latest version.)
The replace template that
you saw earlier in the tutorial was a fairly simple one, but extremely
complex string replacement routines require extremely complex templates. One
of the requirements for XSLT 2.0 was to ease the pain in that area. In
addition, reality has surfaced: Sites with huge traffic flows should avoid
heavy XSLT processing anyway (and let a database do the work whenever it can),
because XSLT has proven to be expensive on heavily trafficked sites. Whether
XSLT 2.0 will change that remains to be seen, but clearly this statement is
much easier to build than the template required in XSLT 1.0:
<p>
<xsl:value-of select="replace(., '(Host)', 'Machine')"/>
</p>
|
The replace() function
is new in XSLT 2.0, and takes three arguments:
- The input string you want to base your search on
- A regular expression to use for singling out the specific characters you want to replace
- The text with which you wish to replace the characters in the second argument

