简体   繁体   English

xpath中的多个条件

[英]Multiple conditions in xpath

I am new to xquery and want to add the conditions on activityStatus as 'A' and maritalStatus as "Married" to get gender of person. 我是xquery的新手,并想将activityStatus的条件添加为“ A”,并将maritalStatus添加为“已婚”以获取人的性别。 I have already created query to add conditions individually but am kind of stuck in case to adding multiple conditions. 我已经创建了要单独添加条件的查询,但是在添加多个条件时有点卡住。 Any pointers will be helpful. 任何指针都会有所帮助。 Thanks in advance. 提前致谢。

Query to get gender on the basis of Marital Status: 根据婚姻状况查询性别:

SELECT PersonInfo.gender_1
  from personData personData,
  xmltable('$personData/Person/personDataCollection/
              personData[(maritalStatus=("Married"))]'
    passing personData."XMLDATA" as "personData"
    columns gender_1 varchar(12) path 'gender'
  ) PersonInfo

...and the document... ...和文件...

<?xml version="1.0" encoding="UTF-8"?>
<Person>
   <activityStatus>A</activityStatus>
   <personDataCollection>
      <personData>
         <personName>
            <lastName>ABC</lastName>
            <firstName>XYZ</firstName>
         </personName>
         <addressCollection>
            <address>
               <line1>123</line1>
               <city>QWERTY</city>
               <state>ASDF</state>
               <postalCode>147852</postalCode>
            </address>
         </addressCollection>
         <maritalStatus>Married</maritalStatus>
         <gender>M</gender>
      </personData>
   </personDataCollection>
</Person>

It sounds like you just want to add a second predicate to your XPath. 听起来您只是想向XPath添加第二个谓词。 If that's the case then you were almost done: 如果是这样,那么您几乎完成了:

$personData/Person[activityStatus="A"]/personDataCollection/personData[maritalStatus="Married"]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM