Red`XIII
18-08-2006, 01:04
Un saluto a tutto il forum.
Sto creando un'applicazione per un esame universitario di Tecnologie Web, e mi sono arenato in un punto sul quale non sono riuscito a trovare documentazione. Devo applicare una trasformazione XSLT su un documento XML per visualizzare i dati tramite un browser.
I file in questione sono i seguenti:
mp3catalog.xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="mp3catalog.xsl"?>
<catalog>
<!--xmlns="http://www.fsangiovanni.it/tech_web/mp3_catalog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.fsangiovanni.it/tech_web/mp3_catalog mp3catalog.xsd"-->
<song pos="1">
<artist>
<first>Gwen</first>
<last>Stefani</last>
<band>false</band>
</artist>
<title>What You Waiting for</title>
<album>Love angel music baby</album>
<year>2004</year>
<time>PT3M41S</time>
<bitrate>232</bitrate>
<encoding>VBR</encoding>
<size>6437766</size>
</song>
<song pos="2">
<artist>
<first>Roxette</first>
<last></last>
<band>true</band>
</artist>
<title>The look</title>
<album>Look sharp!</album>
<year>1988</year>
<time>PT3M57S</time>
<bitrate>128</bitrate>
<encoding>CBR</encoding>
<size>3798233</size>
</song>
<song pos="3">
<artist>
<first>The Black Eyed Peas</first>
<last></last>
<band>true</band>
</artist>
<title>Don't Phunk With My Heart</title>
<album>Monkey Business</album>
<year>2005</year>
<time>PT3M59S</time>
<bitrate>208</bitrate>
<encoding>VBR</encoding>
<size>6227704</size>
</song>
<song pos="4">
<artist>
<first>4 Non Blondes</first>
<last></last>
<band>true</band>
</artist>
<title>Whats up</title>
<album>Bigger, Better, Faster, More!</album>
<year>1992</year>
<time>PT4M55S</time>
<bitrate>218</bitrate>
<encoding>VBR</encoding>
<size>8071204</size>
</song>
<song pos="5">
<artist>
<first>Carmen</first>
<last>Consoli</last>
<band>false</band>
</artist>
<title>Fiori d'arancio</title>
<album>L'eccezione</album>
<year>2002</year>
<time>PT3M33S</time>
<bitrate>256</bitrate>
<encoding>CBR</encoding>
<size>6844544</size>
</song>
<song pos="6">
<artist>
<first>Royksopp</first>
<last></last>
<band>true</band>
</artist>
<title>What Else Is There</title>
<album>The Understanding</album>
<year>2005</year>
<time>PT5M7S</time>
<bitrate>182</bitrate>
<encoding>VBR</encoding>
<size>6988489</size>
</song>
<song pos="7">
<artist>
<first>Chemical Brothers</first>
<last></last>
<band>true</band>
</artist>
<title>Hey Boy Hey Girl</title>
<album>Surrender</album>
<year>1999</year>
<time>PT4M50S</time>
<bitrate>128</bitrate>
<encoding>CBR</encoding>
<size>4648252</size>
</song>
<song pos="8">
<artist>
<first>Subsonica</first>
<last></last>
<band>true</band>
</artist>
<title>Preso Blu</title>
<album>Subsonica</album>
<year>1997</year>
<time>PT4M59S</time>
<bitrate>192</bitrate>
<encoding>CBR</encoding>
<size>7201048</size>
</song>
<song pos="9">
<artist>
<first>Negramaro</first>
<last></last>
<band>true</band>
</artist>
<title>Mentre tutto scorre</title>
<album>Mentre tutto scorre</album>
<year>2005</year>
<time>PT3M20S</time>
<bitrate>320</bitrate>
<encoding>CBR</encoding>
<size>8025988</size>
</song>
<song pos="10">
<artist>
<first>Placebo</first>
<last></last>
<band>true</band>
</artist>
<title>Slave To The Wage</title>
<album>Black Market Music</album>
<year>2000</year>
<time>PT4M6S</time>
<bitrate>192</bitrate>
<encoding>CBR</encoding>
<size>5917706</size>
</song>
</catalog>
mp3catalog.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<title>mp3 catalog</title>
</head>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="catalog">
<h2>my mp3</h2>
<table border="1" bgcolor="9acd32">
<th>First</th>
<th>Last</th>
<th>Title</th>
<xsl:apply-templates/>
</table>
</xsl:template>
<xsl:template match="song">
<tr bgcolor="9acdff">
<td><xsl:value-of select="artist/first"/></td>
<td><xsl:value-of select="artist/last"/></td>
<td><xsl:value-of select="title"/></td>
</tr>
</xsl:template>
</xsl:stylesheet>
Quello che la trasformazione dovrebbe produrre è una tabella in cui vengono riportati i dati principali di ciascuna canzone contenuta nel file xml.
Il problema è il seguente: mantenendo le informazioni relative ai vari namespace nel nodo <catalog> (che mi servono per consentire la validazione tramite file XSD creato a parte) il parser non riesce a riconoscere il nodo radice e la trasformazione non viene eseguita. Appena tolgo qualunque informazione relativa ai namespace, ottengo una bella tabellina ordinata proprio come vorrei.
Non sono riuscito a trovare info su questo problema da nessuna parte, ovunque mi si presentano tutorial che usano come esempi file XML molto (troppo) semplici.
Qualcuno di voi che ne sa abbastanza mi potrebbe dare una mano?
Grazie in anticipo :)
Sto creando un'applicazione per un esame universitario di Tecnologie Web, e mi sono arenato in un punto sul quale non sono riuscito a trovare documentazione. Devo applicare una trasformazione XSLT su un documento XML per visualizzare i dati tramite un browser.
I file in questione sono i seguenti:
mp3catalog.xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="mp3catalog.xsl"?>
<catalog>
<!--xmlns="http://www.fsangiovanni.it/tech_web/mp3_catalog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.fsangiovanni.it/tech_web/mp3_catalog mp3catalog.xsd"-->
<song pos="1">
<artist>
<first>Gwen</first>
<last>Stefani</last>
<band>false</band>
</artist>
<title>What You Waiting for</title>
<album>Love angel music baby</album>
<year>2004</year>
<time>PT3M41S</time>
<bitrate>232</bitrate>
<encoding>VBR</encoding>
<size>6437766</size>
</song>
<song pos="2">
<artist>
<first>Roxette</first>
<last></last>
<band>true</band>
</artist>
<title>The look</title>
<album>Look sharp!</album>
<year>1988</year>
<time>PT3M57S</time>
<bitrate>128</bitrate>
<encoding>CBR</encoding>
<size>3798233</size>
</song>
<song pos="3">
<artist>
<first>The Black Eyed Peas</first>
<last></last>
<band>true</band>
</artist>
<title>Don't Phunk With My Heart</title>
<album>Monkey Business</album>
<year>2005</year>
<time>PT3M59S</time>
<bitrate>208</bitrate>
<encoding>VBR</encoding>
<size>6227704</size>
</song>
<song pos="4">
<artist>
<first>4 Non Blondes</first>
<last></last>
<band>true</band>
</artist>
<title>Whats up</title>
<album>Bigger, Better, Faster, More!</album>
<year>1992</year>
<time>PT4M55S</time>
<bitrate>218</bitrate>
<encoding>VBR</encoding>
<size>8071204</size>
</song>
<song pos="5">
<artist>
<first>Carmen</first>
<last>Consoli</last>
<band>false</band>
</artist>
<title>Fiori d'arancio</title>
<album>L'eccezione</album>
<year>2002</year>
<time>PT3M33S</time>
<bitrate>256</bitrate>
<encoding>CBR</encoding>
<size>6844544</size>
</song>
<song pos="6">
<artist>
<first>Royksopp</first>
<last></last>
<band>true</band>
</artist>
<title>What Else Is There</title>
<album>The Understanding</album>
<year>2005</year>
<time>PT5M7S</time>
<bitrate>182</bitrate>
<encoding>VBR</encoding>
<size>6988489</size>
</song>
<song pos="7">
<artist>
<first>Chemical Brothers</first>
<last></last>
<band>true</band>
</artist>
<title>Hey Boy Hey Girl</title>
<album>Surrender</album>
<year>1999</year>
<time>PT4M50S</time>
<bitrate>128</bitrate>
<encoding>CBR</encoding>
<size>4648252</size>
</song>
<song pos="8">
<artist>
<first>Subsonica</first>
<last></last>
<band>true</band>
</artist>
<title>Preso Blu</title>
<album>Subsonica</album>
<year>1997</year>
<time>PT4M59S</time>
<bitrate>192</bitrate>
<encoding>CBR</encoding>
<size>7201048</size>
</song>
<song pos="9">
<artist>
<first>Negramaro</first>
<last></last>
<band>true</band>
</artist>
<title>Mentre tutto scorre</title>
<album>Mentre tutto scorre</album>
<year>2005</year>
<time>PT3M20S</time>
<bitrate>320</bitrate>
<encoding>CBR</encoding>
<size>8025988</size>
</song>
<song pos="10">
<artist>
<first>Placebo</first>
<last></last>
<band>true</band>
</artist>
<title>Slave To The Wage</title>
<album>Black Market Music</album>
<year>2000</year>
<time>PT4M6S</time>
<bitrate>192</bitrate>
<encoding>CBR</encoding>
<size>5917706</size>
</song>
</catalog>
mp3catalog.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<title>mp3 catalog</title>
</head>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="catalog">
<h2>my mp3</h2>
<table border="1" bgcolor="9acd32">
<th>First</th>
<th>Last</th>
<th>Title</th>
<xsl:apply-templates/>
</table>
</xsl:template>
<xsl:template match="song">
<tr bgcolor="9acdff">
<td><xsl:value-of select="artist/first"/></td>
<td><xsl:value-of select="artist/last"/></td>
<td><xsl:value-of select="title"/></td>
</tr>
</xsl:template>
</xsl:stylesheet>
Quello che la trasformazione dovrebbe produrre è una tabella in cui vengono riportati i dati principali di ciascuna canzone contenuta nel file xml.
Il problema è il seguente: mantenendo le informazioni relative ai vari namespace nel nodo <catalog> (che mi servono per consentire la validazione tramite file XSD creato a parte) il parser non riesce a riconoscere il nodo radice e la trasformazione non viene eseguita. Appena tolgo qualunque informazione relativa ai namespace, ottengo una bella tabellina ordinata proprio come vorrei.
Non sono riuscito a trovare info su questo problema da nessuna parte, ovunque mi si presentano tutorial che usano come esempi file XML molto (troppo) semplici.
Qualcuno di voi che ne sa abbastanza mi potrebbe dare una mano?
Grazie in anticipo :)