0

i'm very new to XML and i have a file that i want to display in the web browser but nothing shows up unless i take away the xsl declaration in the xml file. Can someone tell me how to solve this issue? thanks

XML file

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="XXXXX.xsl"?>
<cookie>
    <name>Grandma White's Cookies</name>
    <serving_size>
        <quantity>1</quantity>
        <unit_of_measurement>package</unit_of_measurement>
    </serving_size>
    <calories>
        <quantity>260</quantity>
        <unit_of_measurement>Calories</unit_of_measurement>
    </calories>
    <fat_calories>
        <quantity>100</quantity>
        <unit_of_measurement>Calories</unit_of_measurement>
    </fat_calories>
    <fat>
        <quantity>11</quantity>
        <unit_of_measurement>grams</unit_of_measurement>
    </fat>
    <saturated_fat>
        <quantity>2</quantity>
        <unit_of_measurement>Calories</unit_of_measurement>
    </saturated_fat>

    <cholesterol>
        <quantity>5</quantity>
        <unit_of_measurement>milligrams</unit_of_measurement>
    </cholesterol>
    <sodium>
        <quantity>210</quantity>
        <unit_of_measurement>milligrams</unit_of_measurement>
    </sodium>
    <protein>
        <quantity>5</quantity>
        <unit_of_measurement>grams</unit_of_measurement>
    </protein>
    <carbohydrates>
        <quantity>36</quantity>
        <unit_of_measurement>grams</unit_of_measurement>
    </carbohydrates>
    <sugar>
        <quantity>15</quantity>
        <unit_of_measurement>grams</unit_of_measurement>
    </sugar>
    <fiber>
        <quantity>2</quantity>
        <unit_of_measurement>grams</unit_of_measurement>
    </fiber>

</cookie>

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"  
    doctype-system = "about:legacy-compat" /> 
    <xsl:template match ="/" >
<html>


            <head>
                <title><xsl:value-of select = "name" /></title>
            </head>

            <body>
                <table border = "1px solid black" >
                    <thead>
                        <tr>
                            <th colspan = "3"><xsl:value-of select = "name" /></th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <th>Serving Size</th>
                            <th><xsl:value-of select = "serving_size/quantity" /></th>
                            <th><xsl:value-of select = "serving_size/unit_of_measurement" /></th>
                        </tr>
                        <tr>
                            <th>Calories</th>
                            <th><xsl:value-of select = "calories/quantity" /></th>
                            <th><xsl:value-of select = "calories/unit_of_measurement" /></th>
                        </tr>
                        <tr>
                            <th>Fat Calories</th>
                            <th><xsl:value-of select = "fat_calories/quantity" /></th>
                            <th><xsl:value-of select = "fat_calories/unit_of_measurement" /></th>
                        </tr>
                        <tr>
                            <th>Fat</th>
                            <th><xsl:value-of select = "fat/quantity" /></th>
                            <th><xsl:value-of select = "fat/unit_of_measurement" /></th>
                        </tr>
                        <tr>
                            <th>Saturated Fat</th>
                            <th><xsl:value-of select = "saturated_fat/quantity" /></th>
                            <th><xsl:value-of select = "saturated_fat/unit_of_measurement" /></th>
                        </tr>
                        <tr>
                            <th>Carbohydrate</th>
                            <th><xsl:value-of select = "carbohydrates/quantity" /></th>
                            <th><xsl:value-of select = "carbohydrates/unit_of_measurement" /></th>
                        </tr>   
                        <tr>
                            <th>Cholesterol</th>
                            <th><xsl:value-of select = "cholesterol/quantity" /></th>
                            <th><xsl:value-of select = "cholesterol/unit_of_measurement"/></th>
                        </tr>
                        <tr>
                            <th>Sugar</th>
                            <th><xsl:value-of select = "sugars/quantity" /><xsl:text> </xsl:text></th>
                            <th><xsl:value-of select = "sugar/unit_of_measurement" /></th>
                        </tr>
                        <tr>
                            <th>Protein</th>
                            <th><xsl:value-of select = "protein/quantity" /></th>
                            <th><xsl:value-of select = "protein/unit_of_measurement" /></th>
                        </tr>
                        <tr>
                            <th>Sodium</th>
                            <th><xsl:value-of select = "sodium/quantity" /></th>
                            <th><xsl:value-of select = "sodium/unit_of_measurement" /></th>
                        </tr>

                        <tr>
                            <th>fiber</th>
                            <th><xsl:value-of select = "fiber/quantity" /><xsl:text> </xsl:text></th>
                            <th><xsl:value-of select = "serving_size/unit_of_measurement" /></th>
                        </tr>


                    </tbody>
                </table>
            </body>
    </html>




</xsl:template>


</xsl:stylesheet>
Bobby
  • 476
  • 5
  • 16
  • What are you expecting to see? I do not think a browser "knows" what to do with a xls file. You just want to see a tree-like display of the xml file ? Opening a properly written xml file in a browser does it. – Veverke Jul 21 '15 at 14:04
  • 1
    "*nothing shows up*" Nothing? Which browser are you using to test this? I definitely see *something* when I try it in Firefox or Safari: http://i.stack.imgur.com/C7Clp.png – michael.hor257k Jul 21 '15 at 14:12
  • i want a table to be displayed in an HTML format – Bobby Jul 21 '15 at 14:13
  • @michael.hor257k thanks for pointing that out, i was testing that on Chrome and yeah it's different in Firefox – Bobby Jul 21 '15 at 14:15
  • im deleting the question since since i check accepted for @michael.hor257k comment – Bobby Jul 21 '15 at 14:18
  • On Chrome, if you open the file with a `file:///` URL, nothing shows up. The developer console, "Resources" section, says, "Unsafe attempt to load URL file:///..../foo.xsl". In Chrome, what sort of URL are you using, `file:` or `http:`? – Robᵩ Jul 21 '15 at 14:18
  • See: http://stackoverflow.com/questions/3828898/can-chrome-be-made-to-perform-an-xsl-transform-on-a-local-file – michael.hor257k Jul 21 '15 at 14:19

0 Answers0