4

Possible Duplicate:
How can I make XSLT work in chrome?

I have this XML file:

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="catalog.xsl"?>

<catalog>
    <album>
        <title>Exodus</title>
        <artist>Bob Marley</artist>
        <country>Jamaica</country>
        <price>19,99</price>
    </album>
    <album>
        <title>Black Album</title>
        <artist>Metallica</artist>
        <country>USA</country>
        <price>20,00</price>
    </album>
    <album>
        <title>Nevermind</title>
        <artist>Nirvana</artist>
        <country>USA</country>
        <price>22,00</price>
    </album>
</catalog>

which links to this XSL file:

<?xml version="1.0" encoding="ISO-8859-1"?>

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

    <xsl:template match="/">
        <html>
            <body>
                <h2>My Catalog</h2>
                <table border="1">
                    <tr bgcolor="#9ACD32">
                        <th>Title</th>
                        <th>Artist</th>
                    </tr>
                    <xsl:for-each select="catalog/album">
                        <tr>
                            <td><xsl:value-of select="title"/></td>
                            <td><xsl:value-of select="artist"/></td>
                        </tr>
                    </xsl:for-each>
                </table>
           </body>
       </html>
    </xsl:template>
</xsl:stylesheet>

When I open the XML file in a browser, I don't see anything being displayed. Since I copied from a tutorial as instructed, I'm not sure what went wrong here. Do you have any clue in terms of what may be causing the lack of display?

Community
  • 1
  • 1
stanigator
  • 10,768
  • 34
  • 94
  • 129
  • It worked for me actually. Browser issue? – keyser May 16 '12 at 07:48
  • @Keyser: I tried this in Chrome. What did you try this in? – stanigator May 16 '12 at 07:49
  • firefox for ubuntu canonical 1.0 (also says 12.0 above that) – keyser May 16 '12 at 07:50
  • It views correctly in Internet Explorer 8 as well as Firefox 3.6, the only browsers I have available at the moment. are you sure you named your xsl file correctly? Its name, according to the XML-File has to be "catalog.xsl", are you sure you did that? – Andreas May 16 '12 at 07:50
  • even with an incorrectly named xsl file he'd see some text from the xml file – keyser May 16 '12 at 07:52
  • See [this answer](http://stackoverflow.com/a/6251757/306030) to a similar question. – forty-two May 16 '12 at 12:30
  • @forty-two: Thanks. Using the answer, I verified this has been the case. – stanigator May 16 '12 at 22:00
  • The problem is that Chrome as a security bug: Chrome doesn't honor the same-origin policy when a file is on the local hard drive. And rather than fix the broken same-origin policy, they just disabled support for xml+xslt. And because IE switched to Chromium, IE is also broken. The only option is to use Internet Explorer or Firefox - which [doesn't suffer from the same vulnerability.](https://bugs.chromium.org/p/chromium/issues/detail?id=4197) – Ian Boyd Jan 13 '22 at 22:26

1 Answers1

4

Depending on XSLT constraints of the browser you use you may see nothing.

I tested your files locally using Chrome 19.0.1084.46 and Firefox 3.6.22.

In Firefox I could view it with no problems, but in Chrome I saw nothing.

When I opened the console tab at developer tools in Chrome it show this message:

Unsafe attempt to load URL file:///temp/web/catalog.xsl from frame with URL file:///temp/web/catalog.xml. Domains, protocols and ports must match.

Then, I started my Tomcat and deployed the 2 files and when I accessed the xml from Chrome voilà, it shows everything as expected.

I'm guessing that you are accessing it using file:/// and this is related to this issue Bug 397894

Flavio Cysne
  • 1,436
  • 8
  • 8