2011-09-30 26 views
6

我有以下代碼似乎失敗。XSL - 在xsl期間轉義撇號:測試時

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

此外,Visual Studio是抱怨說

「表達的預計結束時,找到的」

我怎麼逃脫字符?


XSLT v1.0。 Apache XSL-FO處理器。

+0

難道你的問題涉及到http://stackoverflow.com/questions/646194/xsl-character-escape-problem?如果是這樣,請嘗試:&; – Dan

+0

@丹萊曼 - 那沒用。我不認爲這些問題是相同的。 –

+0

作爲一種解決方法,我將在將C#中的這個字符傳遞給XSLT處理器之前將其刪除。這不適用於所有情況,所以我會把這個問題留給公衆。 –

回答

8

更加簡單 - 使用

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

&apos;適用於XPath 1.0。如果您正在使用XSLT 2.0和XPath 2.0中嘗試雙撇號:

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

尋找在他的回答被Dimitre Novatchev完整解釋Escape single quote in xslt concat function

+1

這沒有奏效。 Visual Studio仍然顯示錯誤。邏輯不能正確執行。 –

+0

@_Phillip:是的,它*是*可以使用相同的技術:) –

6
  1. 聲明一個變量:

    <xsl:variable name="apos" select='"&apos;"'/> 
    
  2. <xsl:when>子句中使用像這樣的變量:

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

+1。您也可以使用'''。 – LarsH