0

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>
1
  • 2
    In XSLT 1.0, you cannot use a function as a location step. As a result, it is not possible to use the method you are attempting to use without performing a preliminary pass to convert the amounts to numbers. Commented Apr 5, 2021 at 14:55

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.