在 XQuery 中获取元素子元素

Fetch element child elements in XQuery

我需要使用 XQuery 获取元素子节点(我正在使用 eXist-db)。

<component> 
  <section classCode="DOCSECT" moodCode="EVN"> 
    <templateId root="1.3.6.1.4.1.19376.1.5.3.1.3.4"/>  
    <id root="2.16.840.1.113883.3.441.1.50.300011.51.26840.61" extension="a20f6b4c8538492d"/>  
    <code code="10164-2" displayName="HISTORY OF PRESENT ILLNESS" codeSystem="2.16.840.1.113883.6.1" codeSystemName="LOINC"/>  
    <title>History of Present Illness</title>  
    <text mediaType="text/x-hl7-text+xml"> 
      <table border="1"> 
        <thead> 
          <tr> 
            <th>Diagnosis</th>  
            <th>Date</th> 
          </tr> 
        </thead>  
        <tbody> 
          <tr> 
            <td ID="ref_9f2173a9a20b4b7989001f10616bca5e_presentIllness_diagnosis_1">Abscess Of Breast Associated With Childbirth</td>  
            <td ID="ref_9f2173a9a20b4b7989001f10616bca5e_presentIllness_date_1">03/20/2013</td> 
          </tr>  
          <tr> 
            <td ID="ref_9f2173a9a20b4b7989001f10616bca5e_presentIllness_diagnosis_5">Fibrocystic Mastopathy</td>  
            <td ID="ref_9f2173a9a20b4b7989001f10616bca5e_presentIllness_date_5">03/20/2013</td> 
          </tr> 
        </tbody> 
      </table> 
    </text> 
  </section> 
</component>

需要获取 <text> 标签的值。

<table border="1"> 
  <thead> 
    <tr> 
      <th>Diagnosis</th>  
      <th>Date</th> 
    </tr> 
  </thead>  
  <tbody> 
    <tr> 
      <td ID="ref_9f2173a9a20b4b7989001f10616bca5e_presentIllness_diagnosis_1">Abscess Of Breast Associated With Childbirth</td>  
      <td ID="ref_9f2173a9a20b4b7989001f10616bca5e_presentIllness_date_1">03/20/2013</td> 
    </tr>  
    <tr> 
      <td ID="ref_9f2173a9a20b4b7989001f10616bca5e_presentIllness_diagnosis_5">Fibrocystic Mastopathy</td>  
      <td ID="ref_9f2173a9a20b4b7989001f10616bca5e_presentIllness_date_5">03/20/2013</td> 
    </tr> 
  </tbody> 
</table>

如果我使用以下查询,结果以 <text> 标记开头。但我只需要其中的 html 内容。

return  $section/text

我尝试 return $section/text/string()return $section/d:text/text() ,但它混合了 <tr><td> 值。

无法进行以下操作,因为有时 <text> 包含没有任何 html 标记的直接值。

return  $section/text/d:table

"If i using the following query, the result start with tag. But i need only the html content inside it.

return $section/text"

而不是 $section/text,您可以 return 直接 text 的子元素,如下所示:$section/text/*.

"Following is not possible because some time <text> contain direct values without any html tag return $section/text/d:table"

在这种情况下,将 * 替换为 node()。后者将匹配任何类型的节点,即元素或文本节点:$section/text/node()