XML shows blank page when linking XSL
Asked Answered
J

3

6

XML file:

<?xml version="1.0"  encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="biblio.xsl"?>

<bibliography>
    <entry type="article">
        <title>A History of MOOCs, Open Online Courses</title>
        <author>Jane Karr</author>
        <year>2014</year>
    </entry> 
    <entry type="article">
        <title>Apple Co-Founder Creates Electronic ID Tags</title>
        <author>John Markoff</author>
        <year>2003</year>
    </entry> 
</bibliography>

XSL file:

<?xml version="1.0"?>

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

<xsl:template match="/">

    <html>
        <body>
            <h2>Bibliography Entries</h2>
            <table border="1">
                <xsl:for-each select="bibliography/entry">
                    <tr>
                        <td><xsl:value-of select="title"/></td>
                        <td><xsl:value-of select="author"/></td>
                        <td><xsl:value-of select="year"/></td>
                    </tr>
                </xsl:for-each>
            </table>
        </body>
    </html>

</xsl:template>
</xsl:stylesheet>

If I don't link the XSLT file to the XML file, my XML file will output the tree structure in my browser's page but if I do link the XSLT file, it will show a blank page.

I am using Chrome, if it helps to know.

Thanks.

Jamisonjammal answered 30/10, 2014 at 20:1 Comment(0)
S
5

I assume you are loading the XML document from the file system and in that case Chrome for security reasons does not apply the linked XSLT, unless you start it with lowered security settings. Use F12 to open the browser console and check whether Chrome shows a message explaining why the Xslt was not applied.

Slalom answered 30/10, 2014 at 20:8 Comment(4)
I did that but it doesn't show anything obvious. All i have written in the console is xml-stylesheet and the xslt isn't present in the sources.Jamisonjammal
Yes, Chrome supports XSLT over HTTP but as I explained not from the local file system. Use Firefox if you need that.Slalom
Did you post the complete code? A closing </xsl:stylesheet> seems to be missing in that case.Slalom
Yes , sorry I forgot to indent it. +1 for explanation and Firefox suggestion. I'm using Firefox now which is working.Jamisonjammal
S
3

If anyone has still problem with launching their XML and XSLT files - right now Mozzila also for security reasons not apply the linked XSLT - you need to change the privacy.file_unique_origin property in about:config to false if you want apply your XSLT styling.

For those who not know - to go into about:config you just need to enter it in the Mozzila search bar.

Sotelo answered 27/12, 2020 at 11:21 Comment(0)
P
1

Your code works quite well. Just start Chrome as follows:

Chrome.exe --allow-file-access-from-files

 

enter image description here

Pulpit answered 30/10, 2014 at 20:8 Comment(2)
I have tried that and doesn't work. I'm thinking it's the browser's fault? I edited my question so it fits with the answer you provided. Unfortunately as I said, it does not work :(Jamisonjammal
Ok, got it - start your Chrome this way: Chrome.exe --allow-file-access-from-files. By default local XSLT processing is disabled for security reasons.Pulpit

© 2022 - 2024 — McMap. All rights reserved.