1
<listings>
   <property rln="r317080" firm="f102" agent="a2140">
      <street>2638 Maple Avenue</street>
      <city>Padua</city>
      <state>WI</state>
      <zip>53701</zip>
      <price>229000</price>
      <style>2 Story Contemporary, Transitional</style>
      <sqfeet>2328</sqfeet>
      <bathrooms>2 1/2</bathrooms>
      <bedrooms>4</bedrooms>
      <garage>2 car, attached</garage>
      <age>22</age>
      <description>Very nice home on a one block dead end street with woods nearby. 
      Very special location for quiet and privacy! Home features open floor plan with 
      large rooms - new patio doors to pretty yard. updates: shingles, vinyl siding, 
      refrig and dishwasher, garage door. Fireplace in family room flanked by great 
      built-ins. add first floor laundry and award winning Padua schools.
      </description> 
   </property>
   <property ...>
      <city>Broxton</city>
    ...
   </property>
   <property ...>
      <city>Cutler</city>
    ...
   </property>
   <property ...>
      <city>Argyle</city>
    ...
   </property>
   <property ...>
      <city>Stratmore</city>
    ...
   </property>
   <property ...>
      <city>Padua</city>
    ...
   </property>
   <property ...>
      <city>Oseola</city>
    ...
   </property>
   <property ...>
      <city>Fenmore</city>
    ...
   </property>
   <property ...>
      <city>Cutler</city>
    ...
   </property>
   <property ...>
      <city>Padua</city>
    ...
   </property>
   <property ...>
      <city>Cutler</city>
    ...
   </property>
   <property ...>
      <city>Oseola</city>
    ...
   </property>
</listings>

在我的教科书(Patrick Carey 的 XML 第 2 版)中,它提供了一个使用“Muenchian Grouping”来查找唯一选择的示例。我不明白的部分是:

它到了这里,在示例的进程中它指出:“ property[generate-id()=generate-id(key("cityNames", "Cutler" )[1])] ”它说这会找到由于索引“[1]”,选择中的第一个“Cutler”。鉴于上面的 XML 将返回“Cutler”

现在示例进展为:“ property[generate-id()=generate-id(key("cityNames", city )[1])] ”这表示这将找到第一个也是唯一一个(因此是唯一的)键内的每个城市。创造了所有城市内部的一组独特价值。鉴于上面的 XML 将返回“Argyle Broxton Cutler Fenmore Padua Stratmore Oseola” (注意没有倍数)

现在,我的问题是:为什么第二个语句返回一系列值,而不仅仅是一个?

谢谢

4

2 回答 2

0

好的,我想我正在寻找的答案是:

property[generate-id()=generate-id(key("cityNames", city)[1])] 此代码查找每个城市的第一个

property[generate-id()=generate-id(key("cityNames", city[1]))] 并且此代码找到所有城市中的第一个

很简单,只是以前看不到。

于 2009-12-13T00:39:55.087 回答
0

定义键时,匹配表达式可以匹配多个节点。按名称访问键时会返回该节点集。

为第一个添加谓词过滤器可确保您最多只能获得从键返回的一个(第一个)节点。

于 2009-12-12T13:40:44.707 回答