在 XSLT 中格式化电话号码

问题描述:

我的 xml 中有一个电话号码,格式为 (515) 123456,我需要像 515123456 一样简单.我使用了下面的代码,但它给我带来了错误

I am having a phone number in my xml in this format like (515) 123456 and I need to have it like simple like 515123456. I used below code and it's throwing me an error

知道如何做到这一点吗?

any idea how this can be done ?

 <xsl:value-of
                select="replace(replace(Mobile1, ') ', ''), '(', '')"
            />

replace() 函数的第二个参数是一个正则表达式模式.括号是正则表达式中的特殊字符,按字面使用时必须转义:

The second argument of the replace() function is a regex pattern. Parentheses are special characters in regex, and must be escaped when used literally:

<xsl:value-of select="replace(replace(Mobile1, '\) ', ''), '\(', '')"/>

或者简单地使用:

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