【问题标题】:xpath multiple conditions with different tagsxpath 具有不同标签的多个条件
【发布时间】:2015-07-25 18:20:03
【问题描述】:

我在验证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"/>。我已经这样做了:

<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>

但是不行,我需要帮助,非常感谢。

这是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>

【问题讨论】:

  • 检查我更新的答案。此外,更新您的问题,而不是发布更新作为答案(例如您的答案已被删除)

标签: xml validation xpath conditional-statements cda


【解决方案1】:

如果我正确理解了这个问题,根据您的规则上下文属性的 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'
]

然后关于“断言测试”的 xpath,因为上下文节点是 &lt;observation&gt;self::cda:entryRelationship 对我来说没有多大意义。试试这个 - 或者可能在开头没有/ - :

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

&lt;entryRelationship&gt; 是上下文节点的子节点,而不是它自己的上下文节点,所以上面的表达式更有意义。

【讨论】:

    猜你喜欢
    • 2012-05-02
    • 1970-01-01
    • 2018-04-11
    • 1970-01-01
    • 1970-01-01
    • 2022-01-03
    • 1970-01-01
    • 1970-01-01
    • 2015-08-03
    相关资源
    最近更新 更多