w3pop.com :: 网络学院 :: XSL/XSLT :: <xsl:sort>
The <xsl:sort> element is used to sort the output.
<xsl:sort>元素用于对结果进行排序。
To sort the output, simply add an <xsl:sort> element inside the <xsl:for-each> element in the XSL file:
如果要对结果进行排序,可以在XSL文件里的<xsl:for-each>元素中添加一个<xsl:sort>元素:
<?xml version="1.0" encoding="ISO-8859-1"?> <xsl:template match="/"> |
Note: The select attribute indicates what XML element to sort on.
注意: 选择(select)属性需要指明对哪些XML元素进行排序。
The result of the transformation above will look like this:
上述代码的转换结果如下:
| Title | Artist |
|---|---|
| Romanza | Andrea Bocelli |
| One night only | Bee Gees |
| Empire Burlesque | Bob Dylan |
| Hide your heart | Bonnie Tyler |
| The very best of | Cat Stevens |
| Greatest Hits | Dolly Parton |
| Sylvias Mother | Dr.Hook |
| Eros | Eros Ramazzotti |
| Still got the blues | Gary Moore |
| Unchain my heart | Joe Cocker |
| Soulsville | Jorn Hoel |
| For the good times | Kenny Rogers |
| Midt om natten | Kim Larsen |
| Pavarotti Gala Concert | Luciano Pavarotti |
| 1999 Grammy Nominees | Many |
| The dock of the bay | Otis Redding |
| When a man loves a woman | Percy Sledge |
| Maggie May | Rod Stewart |
| Stop | Sam Brown |
| Black angel | Savage Rose |
| Picture book | Simply Red |
| Bridge of Spies | T`Pau |
| Red | The Communards |
| Private Dancer | Tina Turner |
| Tupelo Honey | Van Morrison |
| Big Willie style | Will Smith |
View the XML file, View the XSL file, and View the result
XML文件, XSL文件, 以及 最终结果