English 中文(简体)
叛乱团体
原标题:muenchian grouping

I was wondering how this predicate([1]), is hardcoded as 1 always in the muenchian grouping. The concept was not clear for me, after a lot of search. It is explained as the current node, is compared with the 1st group returned by the key. Why does it always compare with the first one that a key is matched? Also why are we giving contact[count(. | key( contacts-by-surname , surname)[1]) = 1], the =1 part? again 1 is hardcoded. I referred the below link

http://www.jenitennison.com/xslt/grouping/muenchian.html

最佳回答

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>
问题回答

请允许我说,我们有一个关键定义:<代码><xsl:key name=“contacts-by-surname”comp=“contact” use=“surname”/>,然后是key(to-by-surname , Doe ),使你在<编码><<<>姓名>>>>>>>>/代码>上添加了所有条码>的内容。 <条码>(联系人与保险人的联系人,Doe )***在“集团”中给你的第一个<代码>contact。

现在处理所有<代码>contact 内容,for-eachapply-templates 我们通常想找到每个群体中的第一个<代码>contact要素。 可通过以下方式做到这一点:<xsl:for-each selected=“contact[count( α > 关键接触-by-surname ,姓)= 1]><xsl:for-each selected=“contact[generate-id()=(关键接触(-by-surname , name) )]”>/code>。

如果你的要求不同,例如,你想确定每个组的最后一个项目,那么你当然可以使用不同的前提,如<代码><xsl:for-each selected=“contact[count(...... : 关键接触-by-surname , 姓)= 1”>;xsl:for-each selected='contact[gener-id()=(key(-by-surname , 姓)[last()]”t;

基本算法是,有两处nes。 外部休息室从每个组中挑选一名代表的节点,内部休息室选择该组的所有节点(包括选择作为代表的节点)。 从一个集团中挑选一名代表最容易的方法是选择第一种,因此选择了“上限编码”<>?





相关问题
When test hanging in an infinite loop

I m tokenising a string with XSLT 1.0 and trying to prevent empty strings from being recognised as tokens. Here s the entire function, based on XSLT Cookbook: <xsl:template name="tokenize"> ...

quick xslt for-each question

Let s say I have an XML document that has this: <keywords> <keyword>test</keyword> <keyword>test2</keyword> <keyword>test3</keyword> <keyword>test4</...

XSLT Transform XML with Namespaces

I m trying to transform some XML into HTML using XSLT. Problem: I can t get it to work. Can someone tell me what I m doing wrong? XML: <ArrayOfBrokerage xmlns:i="http://www.w3.org/2001/...

XSLT output to HTML

In my XSLT file, I have the following: <input type="button" value= <xsl:value-of select="name">> It s an error as it violates XML rule. What I actually want is having a value from an ...

Mangling IDs and References to IDs in XML

I m trying to compose xml elements into each other, and the problem I am having is when there s the same IDs. Basically what I need to do is mangle all the IDs in an xml file, as well as the ...

Sharepoint 2007 Data view Webpart custom parameters

I m sort of new to the custom parameters that can be setup on a DataView Webpart. There are 6 options: - None - Control - Cookie - Form - QueryString - Server Variable I think that None, Cookie and ...

热门标签