Javascript 在 xslt concat 函数中转义单引号

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2887281/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 02:20:08  来源:igfitidea点击:

Escape single quote in xslt concat function

xsltxmljavascript

提问by keshav84

I want to output single quote around $ID variable in the below xsl:value-ofxsl statment.

我想在下面的xsl:value-ofxsl 语句中围绕 $ID 变量输出单引号。

<xsl:value-of select="concat('process[@Ref=',$ID,']')"></xsl:value-of>

currently it prints

目前它打印

process@Ref=87799989

Please let me know how can i achieve this.

请让我知道我怎样才能做到这一点。

Thanks in advance, Keshav

提前致谢,凯沙夫

采纳答案by kennytm

Use &apos;?

使用&apos;?

<xsl:value-of select="concat('process[@Ref=&apos;',$ID,'&apos;]')"></xsl:value-of>

Edit: See Dimitre's answerfor a better solution.

编辑:请参阅Dimitre 的答案以获得更好的解决方案。

回答by Dimitre Novatchev

In XPath 1.0:

在 XPath 1.0 中

You can use the built-in entities &apos;and &quot;

您可以使用内置实体&apos;&quot;

In XSLT 1.0:

在 XSLT 1.0 中

Alternatively, you can define your $Qand $APOSvariables (put the content (the literal " or the literal ' character) in the body of the xsl:variable, not in the selectattribute).

或者,您可以定义您的$Q$APOS变量(将内容(文字“或文字 ' 字符)放在 的主体中xsl:variable,而不是放在select属性中)。

In XPath 2.x(this also means XSLT 2.x and XQuery 1.x)

在 XPath 2.x 中(这也意味着 XSLT 2.x 和 XQuery 1.x)

Simply escape an apostrophe by entering two adjacent apostrophes, escape a quote by entering two adjacent quotes, as defined by the XPath 2.0 language

简单地通过输入两个相邻的撇号来转义一个撇号,通过输入两个相邻的引号来转义一个引号,如 XPath 2.0 语言所定义的

回答by Veloz

To expand on Dimitre's answer, you can use this solution in XSLT:

要扩展 Dimitre 的答案,您可以在 XSLT 中使用此解决方案:

<xsl:variable name="apos">'</xsl:variable>
<xsl:value-of select="concat('process[@Ref=',$apos,$ID,$apos,']')"></xsl:value-of>

回答by Simon

<xsl:value-of
select="concat('process[@Ref=&apos;',$ID,'&apos;]')"></xsl:value-of>

this doesn't work for me. My solution is:

这对我不起作用。我的解决办法是:

<xsl:value-of select="concat(&quot;process[@Ref='&quot;,$oidConstant,&quot;'&quot;)"></xsl:value-of>

回答by user3392863

Easy Example would be

简单的例子是

      <xsl:variable name="varTitle" select="title" />
<xsl:variable name="APOS">'</xsl:variable>
<xsl:value-of select="translate($varTitle, 'any text', $APOS)"/>

This will replace "any text" with ' in my title.

这将在我的标题中用 ' 替换“任何文本”。