XSL Grouping 範例

 

Finding out whether a contact is first in the list returned by the key involves comparing the contact node with the node that is first in the list returned by the key. There are a couple of generic methods of testing whether two nodes are identical:

  1. compare the unique identifiers generated for the two nodes (using generate-id()):

    contact[generate-id() =
            generate-id(key('contacts-by-surname', surname)[1])]
    	  
  2. see whether a node set made up of the two nodes has one or two nodes in it – nodes can’t be repeated in a node set, so if there’s only one node in it, then they must be the same node:

    contact[count(. | key('contacts-by-surname', surname)[1]) = 1]
<xsl:key name="contacts-by-surname" match="contact" use="surname" />
<xsl:template match="records">
	<xsl:for-each select="contact[count(. | key('contacts-by-surname', surname)[1]) = 1]">
		<xsl:sort select="surname" />
		<xsl:value-of select="surname" />,<br />
		<xsl:for-each select="key('contacts-by-surname', surname)">
			<xsl:sort select="forename" />
			<xsl:value-of select="forename" /> (<xsl:value-of select="title" />)<br />
		</xsl:for-each>
	</xsl:for-each>
</xsl:template>
 
以上是範例重點:
 將以下第一個TABLE的資料轉換為第二個TABLE的顯示方式  
欠桶出貨單
出貨日期 出貨單號 送貨員工 鋼瓶類別 規格(KG) 客戶欠桶 已處理 尚欠
2009/07/09 OA0220090709003 仇如玉 標準 20 1 0 1
2009/07/14 OA0220090714001 仇如玉 標準 16 1 0 1
2009/07/14 OA0220090714001 仇如玉 標準 20 1 0 1
欠桶出貨單
出貨日期 出貨單號 送貨員工 鋼瓶類別 規格(KG) 客戶欠桶 已處理 尚欠
2009/07/09 OA0220090709003 仇如玉 標準  20  1  0  1 
2009/07/14 OA0220090714001 仇如玉 標準
標準 
16
20 
1
1 
0
0 
1
1
本篇發表於 XML。將永久鏈結加入書籤。

發表留言