I was wondering how this predicate([1]), is hardcoded as 1 always in
the muenchian grouping.
www.un.org/Depts/DGACM/index_spanish.htm 简单明了:
The key()
function produces all nodes for a given group, and we want to take just one node from any group.
没有保证所有群体在他们中有两个或两个以上节点——有些人可能只有一个节点。
因此,从每个群体中挑选第一个(可能是唯一的)空缺是安全和方便的。
We could equally well do the grouping taking the last node from each group (but this will be less efficient):
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:key name="kNumByMod3" match="num"
use=". mod 3"/>
<xsl:template match=
"num[generate-id()
=
generate-id(key( kNumByMod3 , . mod 3)[last()])
]
">
3k + <xsl:value-of select=". mod 3"/>:
<xsl:text/>
<xsl:copy-of select="key( kNumByMod3 , . mod 3)"/>
</xsl:template>
<xsl:template match="text()"/>
</xsl:stylesheet>
when applied on this XML document:
<nums>
<num>01</num>
<num>02</num>
<num>03</num>
<num>04</num>
<num>05</num>
<num>06</num>
<num>07</num>
<num>08</num>
<num>09</num>
<num>10</num>
</nums>
<produces of the Hope, better grouped results:
3k + 2:
<num>02</num>
<num>05</num>
<num>08</num>
3k + 0:
<num>03</num>
<num>06</num>
<num>09</num>
3k + 1:
<num>01</num>
<num>04</num>
<num>07</num>
<num>10</num>