RE: [xsl] Comments in XPath / XSLT regular expressions?

Subject: RE: [xsl] Comments in XPath / XSLT regular expressions?
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Wed, 26 Jul 2006 10:58:44 +0100
> 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