Send parameter from PHP to XSLT



I'm trying to send an argument to my xsl but I can't succeed.. I don't understand why... I had a look to this link.


I don't think my XSL variable (nameArtist) has the value of my PHP variable ($_GET['name'], for example equals to Brodinski)


My files are :


PHP file :



<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="style.css" />
<title>Zozor - Carnets de voyage</title>
</head>

<body>
<?php

// Load XML file
$xml = new DOMDocument;
$xml->load('artists.xml');

// Load XSL file
$xsl = new DOMDocument;
$xsl->load('artist.xsl');

$process = new XSLTProcessor;
$process->importStyleSheet($xsl);

$process->setParameter('', 'nameArtist', $_GET['name'];);

echo $process->transformToXML($xml);

?>
</body>


XML File :



<?xml version="1.0" encoding="UTF-8"?>
<?xml-model href="artist.rnc" type="application/relax-ng-compact-syntax"?>

<?xml-stylesheet type="text/xsl" href="artist.xsl"?>

<ArtistCollection>
<artist>
<name>Brodinski</name>
<musicCategory>Electronic</musicCategory>
<originalCountry>Germany</originalCountry>
<photo>esfsdfsf</photo>
</artist>

<artist>
<name>Louis Armstrong</name>
<musicCategory>Jazz</musicCategory>
<originalCountry>United States</originalCountry>
</artist>

<artist>
<name>Miles Davis</name>
<musicCategory>Jazz</musicCategory>
<originalCountry>United States</originalCountry>
</artist>
</ArtistCollection>


XSLT File :



<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://ift.tt/tCZ8VR"
xmlns:xs="http://ift.tt/tphNwY"
exclude-result-prefixes="xs"
version="2.0">
<xsl:param name="nameArtist" />
<xsl:template match="/">

<html>
<body>
<h2>Artists</h2>

<p>salut <xsl:value-of select="$nameArtist" /></p>

<xsl:for-each select="ArtistCollection/artist">

<table border="1">
<tr bgcolor="#9acd32">
<th>name</th>
<th>category</th>
<th>country</th>
</tr>
<tr>
<td><xsl:value-of select="name"/></td>
<td><xsl:value-of select="musicCategory"/> </td>
<td><xsl:value-of select="originalCountry"/></td>
</tr>
</table>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>


Thank you for your help :)


No comments:

Post a Comment