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

RE: Comments in XPath / XSLT regular expressions?

Subject: RE: Comments in XPath / XSLT regular expressions?
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Wed, 26 Jul 2006 10:58:44 +0100
RE:  Comments in XPath / XSLT regular expressions?
> Thanks for your advice on this. I understand now the reasons 
> behind not allowing newline-ended comments. After reading 
> Colin Adams comments, and Frans Englich's, I came up with the 
> following as a best-practice for
> ourselves:
> <xsl:variable name="re-extract-filename" >
>     ^.*?              <!-- non-greedy: grab everything -->
>     ([^/\\]+)         <!-- filename in $1  -->
>     \.                <!-- extension-dot  -->
>     [^\.]*$           <!-- extension (not-a-dot*)  -->
> </xsl:variable>
> <xsl:value-of select="replace(., $re-extract-filename, 
> '$1.xml', 'x')" />

That seems an excellent suggestion. Putting the regex in a text node rather
than an attribute node also means that quote characters don't need to be
escaped (and for xsl:analyze-string, curly braces don't need to be doubled).
I'd just add one improvement: add the attribute 'as="xs:string"' to the
variable declaration, so that the value is a string rather than a document. 

Michael Kay

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.