XSLT <xsl:sort>Élément


L'élément <xsl:sort> est utilisé pour trier la sortie.


Où placer les informations de tri

Pour trier la sortie, ajoutez simplement un élément <xsl:sort> à l'intérieur de l'élément <xsl:for-each> dans le fichier XSL :

Exemple

<?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> <body> <h2>Ma collection de CD</h2> <table border="1"> <tr bgcolor="#9acd32"> <th>Titre</th> <th>Artiste</th> </tr> <xsl:for-each select="catalog/cd"> <xsl:sort select="artist"/> <tr> <td><xsl:value-of select="title"/></td> <td><xsl:value-of select="artist"/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>

Essayez-le vous-même »

Remarque :selectL'attribut indique l'élément XML qui doit être trié.


Autres extensions