A voir également:
- Xslt - sort en utilisant une variable
- Ce programme est écrit en python. il construit un mot secret dans une variable mais il ne l'affiche pas. modifiez-le pour qu'il affiche le mot secret. exécutez-le. quel est ce mot secret ? ✓ - Forum Python
- Cliquez sur ce lien. en n'utilisant que le clavier, quel mot obtenez-vous ? ✓ - Forum souris / Touchpad
- Vba range avec variable ✓ - Forum VB / VBA
- Aucun son ne sort de mon pc - Guide
- Faites en sorte que la cellule a1 affiche exactement ce qui est montré sur cette image. quel mot apparaît en b1 ? - Forum Excel
2 réponses
crabs
Messages postés
908
Date d'inscription
lundi 18 avril 2005
Statut
Membre
Dernière intervention
3 août 2008
506
6 nov. 2005 à 21:56
6 nov. 2005 à 21:56
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
Fichier XSL:
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>
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)"/>
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)"/>