2009-12-12 52 views
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> 

在我的書(由帕特里克·凱里XML第二版)提供使用「Muenchian分組的」尋找獨特的選擇的示例。我不明白的部分是這樣的:XSLT - 訪問Key的使用索引 - 例如,在Muenchian分組的

它到達這裏,在它的例子的進程中,它聲明:「 property [generate-id()= generate-id(key(」cityNames「,「卡特勒」)[1])] 「,這表示,這將找到的第一個‘卡特勒’在選擇時,由於索引‘[1]’。這給出上述XML將返回 「庫特勒」

現在的例子進行至這樣的: 「 屬性[生成-ID()=生成-ID(密鑰(」 cityNames」 城市)1])] 「它說,這將找到的鍵值中的每個城市的第一個也是唯一的第一個(因此唯一的)。創建一組所有城市的獨特價值。這給上面的XML將返回「雅閣Broxton卡特勒Fenmore帕多瓦Stratmore Oseola」 (注意,沒有倍數)

現在,我的問題是這樣的:爲什麼第二個語句返回,而不只是一個值的範圍,?

感謝

回答

0

當你定義你的關鍵,本場比賽表達式可以匹配多個節點。當通過名稱訪問密鑰時,返回該節點集。

添加的第一個謂語過濾器確保你只會得到最多一個從鍵返回(第一)節點。

+0

我編輯我的問題的更好的理解,請再看看它,讓我知道你在想什麼。謝謝。 – 2009-12-12 15:38:36

0

好,我想我尋找答案是這樣的:

屬性[生成-ID()=生成-ID(密鑰( 「cityNames」,地點)[1])] 這個代碼是找到第一每個城市的

屬性[生成-ID()=生成-ID(密鑰( 「cityNames」,城市[1]))] 和該代碼找到的第一個足夠所有城市的

容易的,之前只是看不到它。

+1

你的第二個XPath肯定沒有多大意義,你不應該使用它。要找到第一個城市(或者更具體地說,第一個城市),請使用'/ listing/property [1]/city'。 – Tomalak 2009-12-14 10:18:39