0

After searching on this problem on the website, I wasn't finding the exact solution to help me. I use the Chrome browser so there's a possibility that I might be having policy issues? However, I doubt that right now. I have an XML file and its XSL file. The theme of the whole XML file is to store data for a movie theater. Using the w3schools tutorial for XSL transformation on https://www.w3schools.com/xml/xsl_transformation.asp, I was able to fashion it in my own way but when running the XML, my XML page comes up empty. I'd appreciate the help in checking both files out for any mistakes I've made as I am new to the XML & XSL framework. Thanks. Here's my code.

"theater.xml"

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="C:\Users\USER\Desktop\Theater\theater.xsl"?>

<movie_theater>
<movie>
    <movie_title>Fury</movie_title>
    <movie_time>12:00 PM</movie_time>
    <starring>Adam Johnson, Stella Tisdale</starring>
    <date>29/07/20</date>
    <price>Rs150</price>
</movie>

<movie>
    <movie_title>Adventures of Flash</movie_title>
    <movie_time>3:00 PM</movie_time>
    <starring>Alexander Daniels, Richard Nixon</starring>
    <date>30/07/20</date>
    <price>Rs150</price>
</movie>

<movie>
    <movie_title>Batman</movie_title>
    <movie_time>3:00 PM</movie_time>
    <starring>Brandon Phillips</starring>
    <date>31/07/20</date>
    <price>Rs150</price>
</movie>

<movie>
    <movie_title>Wonder Woman</movie_title>
    <movie_time>2:30 PM</movie_time>
    <starring>Remi LaBelle, Stacey Dash</starring>
    <date>30/07/20</date>
    <price>Rs150</price>
</movie>

<movie>
    <movie_title>Lord of the Rings</movie_title>
    <movie_time>1:00 PM</movie_time>
    <starring>Adam Johnson, Alexander Daniels, Richard Nixon, Brandon Phillips</starring>
    <date>01/08/20</date>
    <price>Rs200</price>
</movie>

<movie>
    <movie_title>Avengers Unite</movie_title>
    <movie_time>3:00 PM</movie_time>
    <starring>Adam Johnson, Stella Tisdale, Alexander Daniels, Richard Nixon, Remi LaBelle</starring>
    <date>01/08/20</date>
    <price>Rs150</price>
</movie>

</movie_theater>

"theater.xsl"

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
  <html> 

  <body>
    <h2>Dream Theater</h2>

    <table border="1">
      <tr bgcolor="#9acd32">
        <th style="text-align:left">Movie Title</th>
        <th style="text-align:left">Movie Time</th>
        <th style="text-align:left">Starring</th>
        <th style="text-align:left">Date</th>
        <th style="text-align:left">Price</th>
      </tr>
      
      <xsl:for-each select="movie_theater/movie">
        <tr>
          <td><xsl:value-of select="movie_title"/></td>
          <td><xsl:value-of select="movie_time"/></td>
          <td><xsl:value-of select="starring"/></td>
          <td><xsl:value-of select="date"/></td>
          <td><xsl:value-of select="price"/></td>
        </tr>
      </xsl:for-each>
    </table>
  </body>

  </html>
</xsl:template>
</xsl:stylesheet>
Audu Ibrahim
  • 39
  • 2
  • 9
  • 2
    Chrome won't transform a local file, because security. See https://stackoverflow.com/questions/3828898/can-chrome-be-made-to-perform-an-xsl-transform-on-a-local-file#3839054 (there is nothing wrong with your xslt) – Bryn Lewis Jul 28 '20 at 01:56
  • Thank you. I didn't want to believe that was the case. – Audu Ibrahim Jul 31 '20 at 04:40

1 Answers1

0

If you want to test your code, load it through a web server. If you have python installed then the easiest would be to run python3 -mhttp.server in the directory with the files.

Alex Voss
  • 147
  • 9
  • Hello there, appreciated. However, just to clarify how to use the python server method. I'd be using the command line prompt to navigate to the directory of the files, then use the python command right? – Audu Ibrahim Jul 28 '20 at 12:50
  • Hi, sorry, was busy yesterday. Yes, that is right. The command should print the URL under which you can access your files, e.g., http://0.0.0.0:8000. It allows navigation of directories, which is very useful for local use. – Alex Voss Jul 29 '20 at 08:55
  • Thank you. I will try this. However, since the issue is with Chrome and its policy. I used Microsoft Edge to load the web page and it worked. For that aspect, I can submit the coursework, however, I'll let you know when I try the python method for sure!! – Audu Ibrahim Jul 31 '20 at 04:42