xpath多个条件与不同的标签
问题描述:
我有一个验证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"/>
。我已经这样做了:xpath多个条件与不同的标签
<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>
答
如果我理解正确的问题,根据您的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的“断言测试”,由于上下文节点是<observation>
,self::cda:entryRelationship
对我来说没有多大意义。在开始 - 而不是 - 或者也许试试这个没有/
:
<assert test="/cda:entryRelationship[@typeCode='REFR']">
<entryRelationship>
是上下文节点,而不是上下文节点其自身的孩子,所以上述表达更有意义的尝试。
检查我的更新答案。此外,更新您的问题,而不是张贴更新作为答案(如你的答案已被删除) – har07