對多個欄位進行排序
阿新 • • 發佈:2019-02-12
最近在學習xsl,其中也遇到了不少問題,比如<xsl:sort>對多個欄位排序,因為w3school上面的內容很簡單,所以沒有提及這個
參考了兩個網址:
http://www.runoob.com/xsl/xsl-tutorial.html
http://www.w3school.com.cn/xsl/xsl_languages.asp
<?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <h2>My CD Collection</h2> <table border="1"> <tr bgcolor="#9acd32"> <th>Title</th> <th>Artist</th> </tr> <xsl:for-each select="catalog/cd">
<xsl:sort select="
title"/>
<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>
比如上面的例子中
<xsl:sort select="
title"/>
<xsl:sort select="artist"/>
就是對兩個欄位進行排序。