开发者

XSLT - Accessing Key's by index - For example, in Muenchian Grouping

开发者 https://www.devze.com 2022-12-13 17:35 出处:网络
<listings> <property rln=\"r317080\" firm=\"f102\" agent=\"a2140\"> <street>2638 Maple Avenue</street>
<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<开发者_C百科;/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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号