[XSLT] tri et paramétrage via PHP
Bonjour,
je suis débutant en XML/XSLT et je souhaiterais paramétrer une mise en forme de tri via une transformation XSL.
J'ai un fichier XML bien formé, et un fichier XSL qui contient :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| <?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:param name="mysort">times</xsl:param>
<xsl:param name="mytype">number</xsl:param>
<xsl:param name="myorder">descending</xsl:param>
<html><head>...</head>
<body>
<xsl:for-each select="data/line">
<xsl:sort select="(*|*/*)[name()=$mysort]" data-type="{$mytype}" order="{$myorder}" />
(...)
</xsl:for-each>
</body></html>
</xsl:template>
</xsl:stylesheet> |
Avec ce code, mon tri s'effectue comme il faut.
Cependant, je constate deux problèmes :
1) lorsque je remplace ma déclaration param par
Code:
1 2 3
| <xsl:param name="mysort" select="times"/>
<xsl:param name="mytype" select="number" />
<xsl:param name="myorder" select="descending" /> |
le tri ne marche plus
2) lorsque j'applique la fonction PHP :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| function getXML_T($xslpath, $xmlpath)
{
$sort=$_POST["sort"];
$type=$_POST["type"];
$order=strcmp($_POST["order"],"a")==0 ? "ascending" : "descending";
$xslDoc = new DOMDocument();
$xslDoc->load($xslpath);
$proc = new XSLTProcessor;
$proc->importStylesheet($xslDoc);
$xmlDoc = new DOMDocument();
$xmlDoc->load($xmlpath);
// parameters setting
$proc->setParameter("", "mysort", $sort);
$proc->setParameter("", "mytype", $type);
$proc->setParameter("", "myorder", $order);
return $proc->transformToXML($xmlDoc);
} |
la fonction de tri reste inchangée.
Auriez-vous des idées ??