0

This issue like this one but different.

I have the following xmls:

doc1.xml

<Companies>
<Company id="63919" isSubject="N" refType="SEC">
     <IsRestricted value="true"/>
     <Name>Caixa</Name>
</Company>
<Company id="13332" isSubject="Y" refType="PRI">
      <Name>Banco</Name>
</Company>
</Companies>

doc2.xml

<Companies>
<Company id="13336" isSubject="N" refType="SEC">
    <IsRestricted value="false"/>
    <Name>Santander</Name>
</Company>
<Company id="117436" isSubject="N" refType="PRI">
    <Name>Bankia</Name>
</Company>
</Companies>

doc3.xml

<Companies>
<Company id="12236" isSubject="N" refType="SEC">
    <Name>Inter</Name>
</Company>
<Company id="134562" isSubject="N" refType="PRI">
    <IsRestricted value="true"/>
    <Name>Liber</Name>
</Company>
</Companies>

My searching need exclude the doc where refType=’PRI’ & isSubject=’Y’ & IsRestricted-value=’true’.So, In my example the result should contain doc1.xml and doc2.xml but not doc3.xml.

I thought the following query would do the job:

cts:search(/,
  cts:not-query(
    cts:element-query(xs:QName("Company"),cts:and-query((
    cts:element-attribute-value-query(xs:QName("Company"),xs:QName("refType"),"PRI",(),0),
    cts:element-attribute-value-query(xs:QName("Company"),xs:QName("isSubject"),"Y",(),0),
    cts:element-attribute-value-query(xs:QName("IsRestricted"),xs:QName("value"),"true",(),0) 
   )))
  )
)

But it just returns the doc2.xml. I have update the query:

cts:search(/,
  cts:not-query(
  cts:near-query((
   cts:element-attribute-value-query(xs:QName("Company"),xs:QName("refType"),"PRI",(),0),
   cts:element-attribute-value-query(xs:QName("Company"),xs:QName("isSubject"),"Y",(),0),
   cts:element-attribute-value-query(xs:QName("IsRestricted"),xs:QName("value"),"true",(),0) 
   )))
)

Seems not work either. Only returns doc2.xml.

Community
  • 1
  • 1
Chao Jiang
  • 483
  • 3
  • 13

1 Answers1

0
cts:search(fn:collection("companies"),
cts:not-query(
  cts:and-query((
                  cts:element-attribute-value-query(xs:QName("Company"), 
                  xs:QName("refType"), "PRI"),
                  cts:element-attribute-value-
                 query(xs:QName("Company"),xs:QName("isSubject"),"Y"),
                 cts:element-attribute-value-
                 query(xs:QName("IsRestricted"),xs:QName("value"),"true")))))  

This will give you the desired result.

bosari
  • 1,922
  • 1
  • 19
  • 38