XSLT - 按索引访问键 - 例如,在 Muenchian 分组中

发布于 2024-08-15 08:56:58 字数 2614 浏览 6 评论 0原文

<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 第二版)中,它提供了一个使用“Muenchian 分组”来查找独特选择的示例。我不明白的部分是:

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

现在示例如下:“ 属性[generate-id()=generate-id(key("cityNames", 城市)[1])] “这表示这将找到键中每个城市的第一个也是唯一的第一个(因此是唯一的)。创建一组所有城市的唯一值。给定上面的 XML 将返回“Argyle Broxton Cutler Fenmore Padua Stratmore Oseola”(注意没有倍数)

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

谢谢

<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>

In my textbook (XML 2nd Edition by Patrick Carey) it provides an example of using 'Muenchian Grouping' to find unique selections. The part I don't understand is thus:

It gets to here, in the progression of the example where it states: "
property[generate-id()=generate-id(key("cityNames", "Cutler")[1])]
" which says that this will find the first 'Cutler' in the selection, due to the index of '[1]'. Which given the XML above will return "Cutler"

Now the example progresses to thus: "
property[generate-id()=generate-id(key("cityNames", city)[1])]
" which says that this will find the first and only the first (therefore unique) of each city within the key. Creating a group of unique values of all the city's within. Which given the XML above will return "Argyle Broxton Cutler Fenmore Padua Stratmore Oseola" (note that there is no multiples).

Now, my question is thus: why does the second statement return a range of values, instead of just one?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

孤千羽 2024-08-22 08:56:58

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

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

When you define your key, the match expression can match multiple nodes. That node-set is returned when accessing the key by name.

Adding the predicate filter for the first one ensures that you will only get at most one(the first) node returned from the key.

梓梦 2024-08-22 08:56:58

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

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

[generate-id()=generate-id(key("cityNames", city[1]))]
这段代码发现第一个城市

很容易,只是以前看不到它。

Ok, I suppose the answer I was looking for is thus:

property[generate-id()=generate-id(key("cityNames", city)[1])]
This code finds the first of each city

property[generate-id()=generate-id(key("cityNames", city[1]))]
and this code finds the first of all city's

easy enough, just couldn't see it before.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文