views:

92

answers:

2

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">
  <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>

The XML data is as follows:

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

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
Eval_Penguin
+1  A: 

Xslt is much more verbose

you should use somehting like this :

<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>
jujule
Thank you for a solution to this problem.
Eval_Penguin
And this extra verbosity is the reason it's a shame microsoft won't implement XSLT 2.0!
Eamon Nerbonne