2009-09-30 62 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