How can I change the value of nodes returned by an XPath query?
===

For example, I need my results to be of the form

    <result>
      <French>
        <country>country-name</country>
        <country>country-name</country>
        ...
      </French>
      <German>
        <country>country-name</country>
        <country>country-name</country>
        ...
      </German>
    </result>

but currently, my results are of the form

      <language percentage="100">German</language>
      <language percentage="32">French</language>
      <language percentage="1">German</language>
      <language percentage="100">French</language>
      <language percentage="100">French</language>
      <language percentage="100">German</language>
      <language percentage="99">French</language>
      <language percentage="100">French</language>
      <language percentage="10">French</language>
      <language percentage="32">German</language>
      <language percentage="100">French</language>
      <language percentage="18">French</language>
      <language percentage="65">German</language>

This is my query:
      
     doc("countries.xml")//country/language[contains(text(), "French") or contains(text(), "German")]

The original data looks like this:

    <country name="Afghanistan" population="22664136" area="647500">
        <language percentage="11">Turkic</language>
        <language percentage="35">Pashtu</language>
        <language percentage="50">Afghan Persian</language>
    </country>