I'm learning XSLT via "Beginning XSLT 2.0 From Novice to Professional". Following the source code from the book, I've tried to compile this in Visual Studio 2008 TS:

<xsl:template match="Program">
      <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" />
      <!-- ... -->

The XML data is as follows:

  <Program rating="5" flag="favorite">
    <!-- ... -->
  <!-- ... -->

However, when I compile this code I get:

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

I've checked the website of the book looking for an errata, unfortunately this hasn't been covered. Any pointers would be fantastic.

+1  A: 

Visual studio supports XSLT 1.0. AFAIK no microsoft product supports Xslt 2.0 yet; XQuery 1.0 in SQL Server is the closest you'll get.

Edit: To be clear, the if..then..else syntax is XPath 2.0, not XPath 1.0.

Eamon Nerbonne
Thank you for the reason for this problem
+1  A: 

Xslt is much more verbose

you should use somehting like this :

<xsl:attribute name="src">
<xsl:choose><xsl:when test="@flag='favorite'">favorite</xsl:when><xsl:otherwise>interest</xsl:otherwise></xsl:choose>
Thank you for a solution to this problem.
And this extra verbosity is the reason it's a shame microsoft won't implement XSLT 2.0!
Eamon Nerbonne