Alex Rivera | Logout

Removing non-alphanumeric characters from string in XSL

Asked 2009-08-12T18:36:01.890
11

How do I remove non-alphanumeric characters from a string in XSL?

Edit
Report

2 Answers

20

If you define non-alphanumeric as [^a-zA-Z0-9]:

<xsl:value-of select="
  translate(
    string,
    translate(
      string, 
      'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
      ''
    ),
    ''
  )
" />

Note that this is for XSLT 1.0. In XSLT 2.0 you can work with regexes directly, using replace().

answered 2009-08-12T18:43:50.157
9

For XSLT 2.0 you can use replace() as follows:

<xsl:value-of select="replace(<string>, '[^a-zA-Z0-9]', '')" />
answered 2013-04-18T20:21:21.903

Your Answer