2017-03-16 2 views
1

XML에서 하나의 속성을 기반으로 중복 항목을 제거했습니다. 내 문제는 여러 특성 열을 비교하기 위해 중복을 제거해야합니다.Marklogic : XQuery를 사용하여 중복 제거

Input 
    <Id> 
     <tbl_Keysight_Input Auto_Id="66365" Product_No="10070D" Product_Option="10070D"/> 
     <tbl_Keysight_Input Auto_Id="66365" Product_No="10070D" Product_Option="10070D"/> 
     <tbl_Keysight_Input Auto_Id="66365" Product_No="10070D1" Product_Option="10070D"/> 
     <tbl_Keysight_Input Auto_Id="66365" Product_No="10070D1" Product_Option="10070D"/> 
     <tbl_Keysight_Input Auto_Id="66365" Product_No="10070D" Product_Option="10070D"/> 
     </Id> 

Expected output: 

    <Id> 
    <tbl_Keysight_Input Auto_Id="66365" Product_No="10070D" Product_Option="10070D"/> 
    <tbl_Keysight_Input Auto_Id="66365" Product_No="10070D1" Product_Option="10070D"/> 
    </Id> 

제 요구 사항에 맞는 xquery를 제공해주십시오.

아래 쿼리는 Auto_id를 기반으로합니다. 어떤 preceding-sibling 요소가 deep-equal 경우

for $d in distinct-values(xdmp:directory("/documents/","1")//Id/tbl_Keysight_Input/@Auto_Id) 
let $items := xdmp:directory("/documents/","1")/id/tbl_Keysight_Input[@Auto_Id = $d] 
order by $d 
return 

     for $i in $items [position() le 1] 
     return $i 
+0

['fn : deep-equal()'] (https://docs.marklogic.com/fn:deep-equal)을 사용하고 있습니까? – har07

+0

@ har07 진실과 거짓 진술 만 반환하지만 결과가 필요합니다 – Antony

+0

하나의 속성을 기반으로 중복 항목을 제거 할 때 사용한 전략과 동일한 전략을 적용 할 수 없습니까? 하나의 속성을 비교하는 대신 2 개의 요소 사이의 동일성을 판단하기 위해'deep-equal()'만 사용하십시오 .. – har07

답변

1

비교하는 모든 요소가 동일한 상위 요소 내에있는 것으로 가정하면, 각 tbl_Keysight_Input에 대해 확인할 수 있습니다, 단지 앞의 요소 중 어느 것도 깊은 동일한없는 경우 tbl_Keysight_Input을 반환 . 따라서 동일한 속성을 가진 각 요소 그룹에 대해 선행 복제가 없으므로 첫 번째 요소 만 가져옵니다.

는 그래도 난이 테스트를위한 marklogic 가지고 있지만 XQuery를에 아이디어를 설명해야 다음하지 않습니다

for $x in xdmp:directory("/documents/","1")/id/tbl_Keysight_Input 
where count($x/preceding-sibling::tbl_Keysight_Input[fn:deep-equal(.,$x)]) = 0 
return $x 
1

가장 쉬운 방법은 비교 및 ​​fn:deep-equal()을 사용하는 필터는 것이다. XML 문서 디렉토리가 있고이 요소들을 문서에서 비교하기를 원할 때 임시 XML 구조를 사용해야 할 수도 있습니다.

tbl_Keysight_Input 요소를 모두 선택하여 임시 요소 구조에 넣으면 동일한 요소에 포함될 수 있습니다. 그런 다음 각 tbl_Keysight 요소를 선택하여 반복하고 술어에서 fn:deep-equals()을 사용하여 고유 한 지 확인하십시오.

다음은 작동하지만 디렉토리에있는 문서의 수와 포함 된 tbl_Keysight_Input 요소의 수에 따라 확장되지 않을 수 있습니다.

for $x in <temp>{xdmp:directory("/documents/","1")/id/tbl_Keysight_Input}</temp>/* 
where $x[not(preceding-sibling::*[fn:deep-equal(., $x)])] 
return $x