2015-05-14 66 views
0

我有一個驗證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> 
+0

檢查我的更新答案。此外,更新您的問題,而不是張貼更新作爲答案(如你的答案已被刪除) – har07

回答

0

如果我理解正確的問題,根據您的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>是上下文節點,而不是上下文節點其自身的孩子,所以上述表達更有意義的嘗試。