2014-12-01 175 views
1

到目前爲止,我有一個XML文檔名爲的簡歷可以看出,除其他事項外,包含以下方式的技巧要素:比較元素通過屬性XQuery中

<skills> 
     <skill what = "C" level="0"></skill> 
     <skill what = "Java" level="1"></skill> 
     <skill what = "SQL" level="2"></skill> 
     <skill what = "Lisp" level="3"></skill> 
    </skills> 

我要運行我的查詢的目標是以下:我想找到對的那擁有相同數量的技能,那場比賽中都「做什麼」和「水平」,並輸出結果像這樣的簡歷:

RESUME1,RESUME2 RESUME1,resume3

這是查詢我h大寫:

for $r1 in $resumes/resumes/resume, $r2 in $resumes/resumes/resume 


where $r1/@rID != $r2/@rID and count($r1/skills/skill) = count($r2/skills/skill) 


return ($r1,$r2) 

我需要幫助實際comapring $ r1和$ r2的@what和@level。我試過

data($r1/@what) = data($r1/skills/skill/@what) along with data($r1/skills/skill/@level) = data($r2/@level) 

但我似乎無法得到所需的輸出。有沒有辦法做這種比較?非常感謝。

注:我使用的XML 1.0

回答

2

通過重整你的問題發現的技能,只有其中一人有,問題變得比較容易解決。

let $skills1 := <skills> 
     <skill what = "C" level="0"></skill> 
     <skill what = "Java" level="1"></skill> 
     <skill what = "SQL" level="2"></skill> 
     <skill what = "Lisp" level="3"></skill> 
     <skill what = "XQuery" level="4"></skill> 
    </skills> 
let $skills2 := <skills> 
     <skill what = "C" level="0"></skill> 
     <skill what = "Java" level="1"></skill> 
     <skill what = "SQL" level="2"></skill> 
     <skill what = "Lisp" level="3"></skill> 
    </skills> 

return 
    for $skill in ($skills1, $skills2)/skill 
    where not(
    $skills1/skill[deep-equal(., $skill)] and 
    $skills2/skill[deep-equal(., $skill)] 
) 
    return $skill 

這將返回只有技能集1(XQuery與級別4)的技能。如果您在empty(...)調用中將return子句中的整個flwor表達式包裝在一起,您將獲得true用於匹配技能集,或者如果他們有(任何)不常見的成員,則將得到false

+0

這個工人奇妙。謝謝! :) – 2014-12-01 22:40:44