[XSLT]:在XSLT中删除字符串

AJJ*_*AJJ 1 string xslt removeclass

我在xsl中有字符串"[test]".我需要删除xsl中的这个括号.我怎样才能在XSL中实现这一目标.请帮忙.

我知道这可以做到,但我如何删除'['与下面的代码,

   <xsl:call-template name="string-replace-all">
     <xsl:with-param name="text" select="$string" />
     <xsl:with-param name="replace" select="$replace" />
     <xsl:with-param name="by" select="$by" />
   </xsl:call-template>  
Run Code Online (Sandbox Code Playgroud)

请帮忙删除'['和']'

Sea*_*kin 6

使用translate()函数.

例...

<xsl:call-template name="string-replace-all">
 <xsl:with-param name="text" select="$string" />
 <xsl:value-of select="translate( $text, '[]', '')" />
</xsl:call-template>
Run Code Online (Sandbox Code Playgroud)


nin*_*ths 6

xsl 2.0

replace('[text]','^[(.*)]$','$1')
Run Code Online (Sandbox Code Playgroud)

xsl 1.0

translate('[text]','[]','')
Run Code Online (Sandbox Code Playgroud)

或者

substring-before(substring-after('[text]','['),']')
Run Code Online (Sandbox Code Playgroud)

这些中的任何一个都可以在不同的故障模式下执行您想要的操作。请注意,无论输入是什么,第二个示例都会返回一些内容,但会去除输入中的所有括号。第三个例子只有在它有一个初始左括号和一个终止右括号时才会返回一个字符串,否则它将返回一个空序列。