|
|
|
| xslt - sort en utilisant une variable par smellems |
dimanche 6 novembre 2005 à 20:56:34 |
Salut,
Cela n'est pas possible directement sauf si tu peux calculer directement ta valeur de tri sur des arguments ou des éléments du noeud site. Dans le cas contraire, il faut faire 2 transformations 1 qui fait les calculs, 1 qui fait le tri. Mais pour les calculs y a mieux que XSLT, faut mieux revoir la génération du XML Exemple vis à vis de la première 'option': Fichier XML <?xml version="1.0" encoding="iso-8859-1" ?> <?xml-stylesheet type="text/xsl" href="sort_calc.xsl" ?> <sites> <site nom="1" vu="30" vote="3"/> <site nom="2" vu="30" vote="20"/> <site nom="3" vu="20" vote="3"/> <site nom="4" vu="40" vote="20"/> </sites> Fichier XSL: <?xml version="1.0" encoding="iso-8859-1" ?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output encoding="iso-8859-1" method="html" doctype-public="-//W3C//DTD HTML 4.01//EN" doctype-system="http://www.w3.org/TR/html4/strict.dtd" /> <xsl:template match="/"> <html> <head><title>XML: tri avec calcul</title></head> <body> <table style="width:80%;"> <tr> <th style="width:25%;">site</th> <th style="width:25%;">vote</th> <th style="width:25%;">vu</th> <th style="width:25%;">ratio</th> </tr> <xsl:for-each select="sites/site"> <xsl:sort select="@vote div @vu" data-type="number" order="descending"/> <tr> <td style="text-align:center;"><xsl:value-of select="@nom"/></td> <td style="text-align:center;"><xsl:value-of select="@vote"/></td> <td style="text-align:center;"><xsl:value-of select="@vu"/></td> <td><xsl:value-of select="@vote div @vu"/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet> ..., I think Slackware sounds better than 'Microsoft,' -- Patrick Volkerding - founder and maintainer of Slackware |
merci...
j'aimais mieux mon beau petit calcul: <xsl:variable name="r1" select="rang/r1"/> <xsl:variable name="r2" select="rang/r2"/> <xsl:variable name="r3" select="rang/r3"/> <xsl:variable name="r4" select="rang/r4"/> <xsl:variable name="r5" select="rang/r5"/> <xsl:variable name="total" select="$r1+$r2+$r3+$r4+$r5"/> <xsl:variable name="points" select="$r1+(2*$r2)+(3*$r3)+(4*$r4)+(5*$r5)"/> <xsl:variable name="cote" select="$points div $total"/> mais maintenant ça fonctionne avec... <xsl:sort select="(rang/r1 + (2*rang/r2) + (3*rang/r3) + (4*rang/r4) + (5*rang/r5)) div (rang/r1 + rang/r2 + rang/r3 + rang/r4 + rang/r5)"/> |
| 08/02 18h41 | Utilisation variable pr appelé une feuille | Programmation | 09/02 13h19 | 7 |
| 28/02 11h02 | XSLT - boucle et variable | Programmation | 03/03 15h06 | 6 |
| 10/10 03h26 | Utiliser variable javascript dans code html | Webmastering | 14/10 14h32 | 5 |
| 25/04 16h48 | utiliser variable en PHP | Webmastering | 28/04 10h23 | 3 |