简体   繁体   English

xpath使用不同标签的多个条件

[英]xpath multiple conditions with different tags

I have a problem with validate xml document, I need to arrive to target with tags <templateId root="2.16.840.1.113883.10.20.33.4.4"/> and it <entryRelationship> , both conditions must achieve, because if these two conditions achieve ,I will be able to check if entryRelationship has <templateId root="2.16.840.1.113883.10.20.33.4.2"/> . 我对validate xml文档有问题,我需要使用标签<templateId root="2.16.840.1.113883.10.20.33.4.4"/>及其<entryRelationship>到达目标,这两个条件都必须达到,因为如果这两个条件实现,我将能够检查entryRelationship是否具有<templateId root="2.16.840.1.113883.10.20.33.4.2"/> I have done this: 我已经做到了:

<rule context="//cda:entry/cda:organizer/cda:component/cda:observation[(./templateId/*[@root='2.16.840.1.113883.10.20.33.4.4']) and (./entryRelationship/*[@typeCode='REFR'])]">
   <!--<rule context='*[cda:templateId/@root="2.16.840.1.113883.10.20.33.4.4"]'>-->
   <assert test="self::cda:entryRelationship[@typeCode='REFR']">
      FAIL: CONF-QR-176: The entryRelationship, if present, SHALL contain exactly one [1..1] @typeCode="REFR" (CodeSystem: HL7ActRelationshipType 2.16.840.1.113883.5.1002).  Line: 
      <value-of select="@_line"/>
   </assert>
   <assert test="count(cda:entryRelationship/cda:observation/cda:templateId[@root='2.16.840.1.113883.10.20.33.4.2'])=1">
      FAIL: CONF-QR-177: The entryRelationship, if present,SHALL contain exactly one [1..1] Question Help Text Pattern Observation template (templateId 2.16.840.1.113883.10.20.32.4.19).  Line: 
      <value-of select="@_line"/>
   </assert>
</rule>

but not work,I need help, thanks very much. 但没有用,我需要帮助,非常感谢。

This is xml: 这是xml:

<component>
   <sequenceNumber value="4"/>
   <observation classCode="OBS" moodCode="EVN">
      <!--templateID for the Numeric Response Pattern-->
      <templateId root="2.16.840.1.113883.10.20.33.4.4"/>
      <languageCode></languageCode>
      <entryRelationship typeCode="REFR">
         <!--templateID for Response Media Pattern template-->
         <!--<templateId root="2.16.840.1.113883.10.20.33.4.2"/>-->
      </entryRelationship>
      <id extension="ob4" root="2.16.840.1.113883.3.1817.1.6"/>
      <code code="q4" codeSystem="Continua-Q-OID">
         <originalText>How many hours did you sleep last night?</originalText>
      </code>
      <statusCode code="COMPLETED"/>
      <value xsi:type="INT" value="7"/>
      <referenceRange typeCode="REFV">
         <!--templateID for the Response Reference Range Pattern-->
         <templateId root="2.16.840.1.113883.10.20.33.4.3"/>
         <observationRange>
            <text></text>
            <value xsi:type="IVL_INT">
               <low value="0"/>
               <high value="24"/>
            </value>
         </observationRange>
      </referenceRange>
   </observation>
</component>

If I understand the question correctly, based on your xpath for rule context attribute, you can try this way (formatted for readability) : 如果我正确理解了该问题,则可以基于您的xpath来获取规则上下文属性,可以尝试这种方式(为提高可读性而设置):

//cda:entry
/cda:organizer
/cda:component
/cda:observation[
    templateId/@root='2.16.840.1.113883.10.20.33.4.4' 
        and 
    entryRelationship/@typeCode='REFR'
]

Then regarding xpath for "assert test", since the context node is <observation> , self::cda:entryRelationship doesn't make much sense to me. 然后将xpath用于“断言测试”,因为上下文节点是<observation>self::cda:entryRelationship对我来说没有多大意义。 Try this instead -or maybe without / at the beginning- : 尝试以下方法-或者在开始时不使用/ -

<assert test="/cda:entryRelationship[@typeCode='REFR']">

<entryRelationship> is child of context node, not the context node it self, so the above expression makes more sense to try. <entryRelationship>是上下文节点的子节点,而不是它自身的上下文节点,因此尝试使用上面的表达式更有意义。

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

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