Valid XPath expression doesn't work in XSLT

I'm working on a project that is transforming my .xml file into .html using XSLT, but I run into some problem. I have a XPath expression that is successfully returning the title of the highest grossing movie, but when I try to use it in <xsl:apply-templates select='my xpath'/> or <xsl:template match='my xpath'/> it doesn't work. I'm using Visual Studio and I'm getting an error:

Expected token ')', found '('

This is my first time doing something with XPaths, XSLT and XML so I don't really know what is the problem when my XPath expression works just fine outside of XSLT.

Relevant part of .xml file:

<movie_database>
  <movies>

    <movie>
      <title>Movie 1</title>
      <finance_records>
        <gross>56,000,000 $</gross>
      </finance_records>      
    </movie>
    
    <movie>
      <title>Movie 2</title>
      <finance_records>
        <gross>150,100,055 $</gross>
      </finance_records>       
    </movie>
    
    <movie>
      <title>Movie 3</title>
      <finance_records>
        <gross>100,577,000 $</gross>
      </finance_records>       
    </movie>
  </movies>
</movie_database>

My .xsl file:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output method="html" encoding="UTF-8" indent="yes"/>

  <xsl:template match="/">
    <xsl:text disable-output-escaping='yes'>&lt;!DOCTYPE html&gt;</xsl:text>
    <html>
      <head>
        <title>Movie database</title>
      </head>
      
      <body>
          <xsl:apply-templates select='//movie[not(..//movie//gross/number(translate(.," ,$","")) &gt; .//gross/number(translate(.," ,$","")))]/title'/>   
      </body>
    </html>
  </xsl:template>

  <xsl:template match='//movie[not(..//movie//gross/number(translate(.," ,$","")) &gt; .//gross/number(translate(.," ,$","")))]/title'>
       ... do something
  </xsl:template>
</xsl:stylesheet>

Upvotes: 0

Views: 368

Answers (1)

Michael Kay
Michael Kay

Reputation: 163262

Using a function call like number() on the RHS of the "/" operator is allowed in XPath 2.0 but not in XPath 1.0. You are using an XSLT 1.0 processor, which only supports XPath 1.0.

Upvotes: 1

Related Questions