XSL no funciona [cerrado]
Frecuentes
Visto 7,323 veces
1
I have got this strange problem.XSL is not working with xml.This is my xml and xsl code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xsl-stylesheet type= "text/xsl" href= "w3c.xsl"?>
<catalog>
<cd>
<title>Greatest Hits</title>
<artist>Dolly Parton</artist>
<country>USA</country>
<company>RCA</company>
<price>9.90</price>
<year>1982</year>
</cd>
<cd>
<title>Eros</title>
<artist>Eros Ramazzotti</artist>
<country>EU</country>
<company>BMG</company>
<price>9.90</price>
<year>1997</year>
</cd>
<cd>
<title>Romanza</title>
<artist>Andrea Bocelli</artist>
<country>EU</country>
<company>Polydor</company>
<price>10.80</price>
<year>1996</year>
</cd>
</catalog>
Este es mi xsl:
<?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 xmlns="http://www.w3.org/1999/xhtml">
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<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>
Nota:
I took this code from W3C and hence it's a working one.I have googled a lot but couldn't find any working solution.I have used ie,firefox and chrome doesn't work in any of them.I have tested it in my remote server doesn't work either.The error I get is "This XML file does not appear to have any style information associated with it. The document tree is shown below.".The same error occurs.In the href I have tried all possible links from full path to just file name.I have also tried chrome with --allow-file-access-from-files but doesn't work.Please help me fix this.
2 Respuestas
3
Note that the second line of your XML file says:
<?xsl-stylesheet type= "text/xsl" href= "w3c.xls"?>
Notice the w3c.xls (instead of xsl ?) what are your filenames?
And notice that is is xml-stylesheet
no, xsl-stylesheet
.
Entonces esto debería hacerlo:
<?xml-stylesheet type= "text/xsl" href= "w3c.xsl"?>
Respondido 28 ago 12, 14:08
Yep. Missing the reference to the stylesheet. - plumaj
It doesn't work.That was a typing mistake. - user1613360
Works Thank You very much.You saved my day. - user1613360
Don't forget to mark as answered :) - Gerardo Versluis
0
I cant reproduce this problem.
When the provided XSLT stylesheet:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<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>
is applied (with all 9 different XSLT processors I have available) to the provided XML document:
<catalog>
<cd>
<title>Greatest Hits</title>
<artist>Dolly Parton</artist>
<country>USA</country>
<company>RCA</company>
<price>9.90</price>
<year>1982</year>
</cd>
<cd>
<title>Eros</title>
<artist>Eros Ramazzotti</artist>
<country>EU</country>
<company>BMG</company>
<price>9.90</price>
<year>1997</year>
</cd>
<cd>
<title>Romanza</title>
<artist>Andrea Bocelli</artist>
<country>EU</country>
<company>Polydor</company>
<price>10.80</price>
<year>1996</year>
</cd>
</catalog>
a correct result is produced:
<?xml version="1.0" encoding="utf-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>
<tr>
<td>Greatest Hits</td>
<td>Dolly Parton</td>
</tr>
<tr>
<td>Eros</td>
<td>Eros Ramazzotti</td>
</tr>
<tr>
<td>Romanza</td>
<td>Andrea Bocelli</td>
</tr>
</table>
</body>
</html>
Respondido 28 ago 12, 14:08
Thanks for your reply.Problem got fixed already.I used <xsl-stylesheet> instead of <xml-stylesheet>. - user1613360
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas xml google-chrome xslt or haz tu propia pregunta.
meta.stackexchange.com/questions/91040/… - LarsH