user3836593
user3836593

Reputation: 43

XSLT 2.0 - How to replace '(' and ')' to empty from the string?

I am looking for this solution in xslt 2.0:

Input: +47(12)1234567

Output: +47121234567

I tried to use this:

replace(replace('$Input', '(',''), ')','')

But it throws an error as '(' and ')' are unable to be escaped with the above code.

Please can some one point out the correct solution.

Thank you.

Upvotes: 1

Views: 2614

Answers (3)

Amrendra Kumar
Amrendra Kumar

Reputation: 1816

Use this: <xsl:value-of select="replace($input, '\(|\)','')"/>

Upvotes: 0

Martin Honnen
Martin Honnen

Reputation: 167716

I would put both characters into square brackets in a single replace call replace($input, '[()]', '').

Upvotes: 3

wasmachien
wasmachien

Reputation: 1009

Parentheses are reserved characters in regex, which is what the replace function takes as argument.

The easiest solution is to use translate(), in this case:

 <xsl:value-of select="translate('+47(12)1234567', '()', '')"/>

Alternatively, you can escape the parentheses with a backslash.

Upvotes: 1

Related Questions