2009-09-30 60 views
1

我正在通過「Beginning XSLT 2.0 From Novice to Professional」學習XSLT。繼從書的源代碼,我試圖在Visual Studio 2008 TS編譯此:Visual Studio 2008中的「無效的XPath表達式」錯誤TS

<xsl:template match="Program"> 
    <div> 
    <p> 
     <xsl:if test="@flag"> 
     <img src="{if (@flag = 'favorite') then 'favorite' else 'interest'}.gif" 
      alt="[{if (@flag = 'favorite') then 'Favorite' else 'Interest'}]" 
      width="20" height="20" /> 
     </xsl:if> 
     <!-- ... --> 
    </p> 
    </div> 
</xsl:template> 

的XML數據如下:

<Channel> 
    <Name>BBC1</Name> 
    <Program rating="5" flag="favorite"> 
    <!-- ... --> 
    </Program> 
    <!-- ... --> 
</Channel> 

然而,當我編譯這段代碼我得到:

 
'string(if (@flag = 'favorite') then 'favorite' else 'interest')' 
is an invalid XPath expression. 

我檢查了這本書的網站尋找勘誤,不幸的是這並沒有被覆蓋。任何指針都會很棒。

+0

@Eval_Penguin:請不要將'折磨自己 「<」''以 「<」'。您可以使用「0101」代碼格式編輯器按鈕,也可以使用四個空格縮進代碼塊。你甚至會得到免費的語法高亮。 ;-) – Tomalak 2009-09-30 11:29:01

回答

1

Visual Studio支持XSLT 1.0。 AFAIK還沒有微軟產品支持Xslt 2.0; SQL Server中的XQuery 1.0是最接近你的。

編輯:要明確,if..then..else語法是XPath 2.0,而不是XPath 1.0。

+0

感謝您爲此問題的原因 – AdamWhite 2009-09-30 10:55:07

1

XSLT是更冗長

你應該使用服用點是這樣的:

<img> 
<xsl:attribute name="src"> 
<xsl:choose><xsl:when test="@flag='favorite'">favorite</xsl:when><xsl:otherwise>interest</xsl:otherwise></xsl:choose> 
</xsl:attribute> 
</img> 
+0

感謝您解決此問題的解決方案。 – AdamWhite 2009-09-30 10:54:32

+0

而這種額外的冗長是它羞恥的原因微軟不會實現XSLT 2.0! – 2009-09-30 11:20:05