XSL - 在 xsl:when 测试中转义单引号

8
我有以下代码,看起来似乎失败了。
<xsl:when test="$trialSiteName = 'Physician&apos;s Office'">

此外,Visual Studio 报错显示:
"Expected end of expression, found 's'"
我该如何转义这个字符?
XSLT v1.0。Apache XSL-FO 处理器。

你的问题是否与https://dev59.com/xkbRa4cB1Zd3GeqP4eHb有关?如果是,请尝试:&apos; - Dan
@Dan Lehmann - 那个方法没有起作用。我认为那些问题不是一样的。 - P.Brian.Mackey
作为一种解决方法,我将在传递给XSLT处理器之前在C#中删除此字符。这种方法并不适用于所有情况,因此我会保留这个问题的开放性。 - P.Brian.Mackey
4个回答

9

更简单的方法--使用:

   <xsl:when test="$trialSiteName = &quot;Physician&apos;s Office&quot;">

7
  1. Declare a variable:

    <xsl:variable name="apos" select='"&apos;"'/>
    
  2. Use the variable like this in the <xsl:when> clause:

    <xsl:when test="$trialSiteName = concat('Physician', $apos, 's Office')">
    

5
你也可以使用<xsl:variable name="apos">'</xsl:variable> - LarsH

1

&apos; 在XPath 1.0中有效。如果您正在使用XPath 2.0的XSLT 2.0,请尝试使用双撇号:

<xsl:when test="$trialSiteName = 'Physician''s Office'">

在Dimitre Novatchev的回答中查找逃逸XSLT concat函数中的单引号的完整解释。


1
这个不起作用。Visual Studio 仍然显示错误。逻辑执行不正确。 - P.Brian.Mackey
@_Phillip:是的,使用相同的技术是可能的 :) - Dimitre Novatchev

1
&quot;之间,您可以添加任何特殊字符。
<xsl:when test="$trialSiteName = &quot;Physician's what ever special charactors plainly add Office&quot;">

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接