1

My xml file is shown on the firefox browser with just the data inside. The stylesheet doesn't seem to work even when it says it is linked. When I inspect, the console says " Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at file:///C:/Users/Aner/Desktop/part3.xsl. (Reason: CORS request not http)." I do not understand how to solve this problem. Please help !!

My xml file:

<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="part3.xsl"?>
<forecast queryTime="30/7/2021 14:10:20" queryLocation="Singapore">
  <weather yyyymmdd="20210617">
    <year>2021</year>   
    <month>6</month>
    <date>17</date>
    <dayOfWeek>Thu</dayOfWeek> 
    <overall>Considerable clouds</overall>
    <overallCode>cloudy</overallCode>
    <highest>29</highest>
    <lowest>19</lowest>
  </weather>
  <weather yyyymmdd="20210612">
    <year>2021</year>   
    <month>6</month>
    <date>12</date>
    <dayOfWeek>Sat</dayOfWeek> 
    <overall>Cloudy with a thunderstorm</overall>
    <overallCode>thunderstorm</overallCode>
    <highest>28</highest>
    <lowest>23</lowest>
  </weather>
  <weather yyyymmdd="20210709">
    <year>2021</year>   
    <month>7</month>
    <date>09</date>
    <dayOfWeek>Fri</dayOfWeek> 
    <overall>A morning shower, then rain</overall>
    <overallCode>rain</overallCode>
    <highest>29</highest>
    <lowest>23</lowest>
  </weather>
  <weather yyyymmdd="20210601">
    <year>2021</year>   
    <month>6</month>
    <date>01</date>
    <dayOfWeek>Tue</dayOfWeek> 
    <overall>Partly sunny</overall>
    <overallCode>partlySunny</overallCode>
    <highest>31</highest>
    <lowest>28</lowest>
  </weather>
  <weather yyyymmdd="20210802">
    <year>2021</year>   
    <month>8</month>
    <date>02</date>
    <dayOfWeek>Mon</dayOfWeek> 
    <overall>Plenty of sunshine</overall>
    <overallCode>sunny</overallCode>
    <highest>35</highest>
    <lowest>24</lowest>
  </weather>
</forecast>

My xsl code:

<?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:output method="xml" indent="yes" encoding="UTF-8"/>
    
    <xsl:template match="/forecast">
        <html>
            <head>
                <title>Singapore</title>
            </head>
            <body>
                <xsl:value-of select="queryLocation"/><xsl:value-of select="@queryTime"/>
                <table border="1">
                    <tr bgcolor="#ffa500">
                        <th>Date</th>
                        <th>Mon</th>
                    </tr>
                </table>
                
            </body>
        </html>
    </xsl:template>
</xsl:stylesheet>

Just a simple code to try out but it didn't work.

Geminianer
  • 21
  • 4

0 Answers0