xsl-list
[Top] [All Lists]

[xsl] Quoting meta characters for a regular expression character class

2008-08-25 11:16:17
I currently am using XSL 2.0 and have a template that basically looks like:

  <xsl:template name="chopPunctuation" as="xsd:string">
    <xsl:param name="chopString" as="xsd:string" required=yes" />
    <xsl:param name="punctuation" as="xsd:string" required="no" 
select="string('.:,;/ ')" />
    <xsl:variable name="rePattern" as="xsd:string" 
select="concat('[',$punctuation,']+$')" />
    <xsl:value-of select="replace($chopString,$rePattern,'')" />
  </xsl:template>

Basically the template accepts a string and a list of characters to remove from 
the end of the string.  The problem here is that I know I just cannot drop 
$punctuation into the created on-the-fly regular expression $rePattern since I 
have to account for any meta characters that $punctuation might have.  I'm sure 
someone has come across this issue and has a function that will quote the 
necessary meta characters for a regular expression character class.  Seems like 
this should be part of the standard XPath 2.0 functions to hide the details of 
regular expressions.  After all Perl has had quotemeta() for quite some time...
 

Thanks, Andy.



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--