1

I have a simple XML file: customer.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="web.xsl"?>
<purple> 
    <customer cid="1">
        <fname>John</fname> 
        <lname>Klingard</lname> 
        <apt>27</apt> 
        <street>30th Winstonhut St.</street> 
        <pobox>199183</pobox> 
    </customer>
</purple>

This is my XSL file: web.xsl

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
<xsl:template match="/">
    <html> 
        <head> 
            <title>Customer</title> 
        </head> 
        <body> 
            <xsl:for-each select="//customer[@cid='1']">
            <xsl:value-of select="fname"/> <br/>
            <xsl:value-of select="lname"/> <br/>    
            </xsl:for-each>
        </body>
    </html>
</xsl:template> 
</xsl:stylesheet> 

The problem is that there is no output on the browser from the query. I am using Google Chrome. I suspect that there might be something wrong with the XPath query itself. But, am I missing anything else?

kjhughes
  • 106,133
  • 27
  • 181
  • 240
Arjun
  • 817
  • 3
  • 16
  • 28
  • 4
    Do a search for XSLT + Chrome. – michael.hor257k Mar 27 '16 at 06:45
  • @har07 It doesn't work on IE either! – Arjun Mar 27 '16 at 06:56
  • 2
    I tried your samples at http://home.arcor.de/martin.honnen/xslt/test2016032701.xml with the stylesheet http://home.arcor.de/martin.honnen/xslt/test2016032701.xsl and it works fine with Firefox, IE, Chrome and Edge. – Martin Honnen Mar 27 '16 at 08:43
  • 1
    Please state what output you are expecting I tried it with Firefox 44 and got "John\nKlingard\n" so I believe that it works for me. I also tried Chrome 49 but got a blank page. – ssimm Mar 27 '16 at 10:19
  • @MartinHonnen Thanks but what surprises me is that it works online but when I download it and run the local files, it gives me a blank page. – Arjun Mar 27 '16 at 10:47
  • @ssimm Yes, that's exactly what I'm expecting as output! Also, thanks.. I tried it with Firefox and it works! I'm switching to Firefox to continue with the work. – Arjun Mar 27 '16 at 10:53
  • @michael.hor257k tried to direct you to the answer 6 hours ago. Did you read his suggested references? Chrome won't run local XSLT due to security concerns. See details in the links contained in the duplicate notice. – kjhughes Mar 27 '16 at 13:12
  • @kjhughes Yes, I did read it. It was suggested that I run Chrome from cmd using the --allow-file-access-from-files flag. I attempted this yet it never worked. – Arjun Mar 27 '16 at 14:47
  • You've drawn the wrong conclusion. [**To run XSLT in the browser**](http://stackoverflow.com/a/29942399/290085), ***load from a server*** [**instead of from local files**](http://stackoverflow.com/a/33801287/290085). – kjhughes Mar 27 '16 at 17:25
  • 1
    @kjhughes Oh I understand now! Thank you so much.. I ran it on an Apache server and it works! – Arjun Mar 27 '16 at 19:09

0 Answers0