Arun M R Nair
Arun M R Nair

Reputation: 653

Fetch element child elements in XQuery

I need to fetch the element child node using XQuery (i am using 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>

need to fetch the value for <text> tag.

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

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

return  $section/text

I try for return $section/text/string() and return $section/d:text/text() , but it getting mix of <tr> and <td> values.

Following is not possible because some time <text> contain direct values without any html tag.

return  $section/text/d:table

Upvotes: 0

Views: 778

Answers (1)

har07
har07

Reputation: 89295

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

return $section/text"

Instead of $section/text, you can return direct child element of text like so : $section/text/*.

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

In this case, replace * with node(). The latter will match any kind of node i.e either element or text node : $section/text/node()

Upvotes: 3

Related Questions