2007年1月,W3C发布了XSLT2.0规范,2009年发布了XSLT2.1,XSLT3.0预计今年发布!
分组
函数:node-set current-group():该函数返回分组所包含的节点集。
函数:node-set current-grouping-key():该函数返回当前分组的条件(控制分分组的关键节点)。
<!-- Category: instruction -->
<xsl:for-each-group
select = expression
group-by? = expression
group-adjacent? = expression
group-starting-with? = pattern
group-ending-with? = pattern
collation? = { uri }>
<!-- Content: (xsl:sort*, sequence-constructor) -->
</xsl:for-each-group>
属性详解:
1:select:用于指定需要分组的节点;
2:group-by:用于控制分组的关键节点;
3:group-adjacent:用于控制分组的关键节点,并且只将相邻的元素分为一组;
4:group-starting-with:指定分组的开始节点;
5:group-ending-with:指定分组的结束节点;
The following example groups a list of nodes based on common values. The resulting groups are numbered but unsorted, and a total is calculated for each group.
Source XML document:
<cities> <city name="Milano" country="Italia" pop="5"/> <city name="Paris" country="France" pop="7"/> <city name="München" country="Deutschland" pop="4"/> <city name="Lyon" country="France" pop="2"/> <city name="Venezia" country="Italia" pop="1"/> </cities>
Desired output:
<table> <tr> <th>Position</th> <th>Country</th> <th>List of Cities</th> <th>Population</th> </tr> <tr> <td>1</td> <td>Italia</td> <td>Milano, Venezia</td> <td>6</td> </tr> <tr> <td>2</td> <td>France</td> <td>Lyon, Paris</td> <td>9</td> </tr> <tr> <td>3</td> <td>Deutschland</td> <td>München</td> <td>4</td> </tr> </table>
Solution:
<table xsl:version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<tr>
<th>Position</th>
<th>Country</th>
<th>City List</th>
<th>Population<