Retrieve Oxford Dictionaries API Translation Data as XML with XQuery and BaseX

Retrieve Oxford Dictionaries API Translation Data as XML with XQuery and BaseX
My notes from the Vanderbilt University XQuery Working Group

We retrieved translation data from the Oxford Dictionaries application programming interface (API) and returned Extensible Markup Language (XML) with XQuery, an XML query language, and BaseX, an XML database engine and XQuery processor. This tutorial illustrates how to retrieve translation data—words and example sentences—as XML from the Oxford Dictionaries API with XQuery and BaseX.

The Oxford Dictionaries API returns JavaScript Object Notation (JSON) responses that yield undesired XML structures when converted automatically with BaseX. Fortunately, we’re able to use XQuery to fill in some blanks after converting JSON to XML. My GitHub repository od-api-xquery contains XQuery code for this tutorial.

Retrieve translation data

We can retrieve translation data as XML from the Oxford Dictionaries API with XQuery in a manner similar to using the dictionary endpoint, and we can get started with the code template od-api.xquery. First, we import an XQuery translation library module, od-api-basex.xquery, and assign it the namespace od-api. Second, we replace myId and myKey with our own Oxford Dictionaries API Credentials. Third, we set options, such as $source-lang and $target-lang, following the “Translation” section of the Oxford Dictionaries API documentation, to retrieve translation data, such as words and example sentences. Finally, we request translation data using $translation(). Sample XQuery code for retrieving translation data as XML for the word ‘change’ follows:

xquery version "3.1" encoding "UTF-8";

import module namespace od-api="od-api-basex" at "https://raw.githubusercontent.com/AdamSteffanick/od-api-xquery/master/od-api-basex.xquery";

let $id := "myId"
let $key := "myKey"

let $source-lang := "en"
let $target-lang := "es"

let $translation := od-api:translation($source-lang, ?, $target-lang, $id, $key)

return $translation("change")

In the XQuery code above, we use return $translation("change") to trigger our request to the Oxford Dictionaries API. The library module automatically alters the argument of $translation() by replacing spaces with underscores, forcing lower-case characters, and encoding reserved characters. For example, returning $translation("béchamel") sends the word_id parameter b%C3%A9chamel to the Oxford Dictionaries API. Similarly, returning $translation("European Union") sends the word_id parameter european_union. Returning $translation("change") triggers a request to the Oxford Dictionaries API through the use of a partial function application. The actual request is sent by calling the library module’s od-api:translation() function, whose argument ? is assigned its value by $translation("change"). Running our XQuery code above with BaseX returns the following result:

<translation input="change" language="en" target-language="es">
  <metadata>
    <provider>Oxford University Press</provider>
    <date>Fri, 17 Feb 2017 14:30:00 GMT</date>
  </metadata>
  <results>
    <result>
      <id>change</id>
      <language>en</language>
      <type>headword</type>
      <word>change</word>
      <lexicalEntries>
        <lexicalEntry>
          <language>en</language>
          <lexicalCategory>Verb</lexicalCategory>
          <text>change</text>
          <entries>
            <entry>
              <grammaticalFeatures>
                <grammaticalFeature>
                  <text>Intransitive</text>
                  <type>Subcategorization</type>
                </grammaticalFeature>
                <grammaticalFeature>
                  <text>Present</text>
                  <type>Tense</type>
                </grammaticalFeature>
              </grammaticalFeatures>
              <homographNumber>002</homographNumber>
              <senses>
                <sense>
                  <examples>
                    <example>
                      <text>she's a changed person since she met him</text>
                      <translations>
                        <translation>
                          <language>es</language>
                          <text>desde que lo conoció es otra</text>
                        </translation>
                      </translations>
                    </example>
                    <example>
                      <text>I can't believe how much she's changed</text>
                      <translations>
                        <translation>
                          <language>es</language>
                          <text>me parece increíble lo mucho que ha cambiado</text>
                        </translation>
                      </translations>
                    </example>
                    <example>
                      <text>to change in shape/size</text>
                      <translations>
                        <translation>
                          <language>es</language>
                          <text>cambiar de forma/tamaño</text>
                        </translation>
                      </translations>
                    </example>
                    <example>
                      <text>to change into sth</text>
                      <translations>
                        <translation>
                          <language>es</language>
                          <text>convertirse / transformarse en algo</text>
                        </translation>
                      </translations>
                    </example>
                    <example>
                      <text>customs have changed</text>
                      <translations>
                        <translation>
                          <language>es</language>
                          <text>las costumbres han cambiado</text>
                        </translation>
                      </translations>
                    </example>
                  </examples>
                  <id>b-en-es0008145.044-se1-3</id>
                  <translations>
                    <translation>
                      <language>es</language>
                      <text>cambiar</text>
                    </translation>
                  </translations>
                </sense>
                <sense>
                  <examples>
                    <example>
                      <text>I've changed to a new dentist</text>
                      <translations>
                        <translation>
                          <language>es</language>
                          <text>he cambiado de dentista</text>
                        </translation>
                      </translations>
                    </example>
                    <example>
                      <text>the scene changes to wartime Rome</text>
                      <translations>
                        <translation>
                          <language>es</language>
                          <text>la escena pasa / se traslada a Roma durante la guerra</text>
                        </translation>
                      </translations>
                    </example>
                    <example>
                      <text>the cast changes every three months</text>
                      <translations>
                        <translation>
                          <language>es</language>
                          <text>el reparto cambia cada tres meses</text>
                        </translation>
                      </translations>
                    </example>
                    <example>
                      <text>her smile changed to a frown</text>
                      <translations>
                        <translation>
                          <language>es</language>
                          <text>dejó de sonreír y frunció el ceño</text>
                        </translation>
                      </translations>
                    </example>
                    <example>
                      <text>the traffic lights changed</text>
                      <translations>
                        <translation>
                          <language>es</language>
                          <text>cambió el semáforo</text>
                        </translation>
                        <translation>
                          <language>es</language>
                          <text>cambiaron las luces (del semáforo)</text>
                        </translation>
                      </translations>
                    </example>
                  </examples>
                  <id>b-en-es0008145.045-se1-3</id>
                  <translations>
                    <translation>
                      <language>es</language>
                      <text>cambiar</text>
                    </translation>
                  </translations>
                </sense>
                <sense>
                  <id>b-en-es0008145.046-se1-3</id>
                  <translations>
                    <translation>
                      <language>es</language>
                      <text>cambiante</text>
                    </translation>
                  </translations>
                </sense>
                <sense>
                  <examples>
                    <example>
                      <text>change out of those wet clothes</text>
                      <translations>
                        <translation>
                          <language>es</language>
                          <text>quítate esa ropa mojada</text>
                        </translation>
                      </translations>
                    </example>
                    <example>
                      <text>to get changed</text>
                      <translations>
                        <translation>
                          <language>es</language>
                          <text>cambiarse</text>
                        </translation>
                      </translations>
                    </example>
                    <example>
                      <text>she changed into a black dress</text>
                      <translations>
                        <translation>
                          <language>es</language>
                          <text>se cambió y se puso un vestido negro</text>
                        </translation>
                      </translations>
                    </example>
                    <example>
                      <text>I'm going to change into something more comfortable</text>
                      <translations>
                        <translation>
                          <language>es</language>
                          <text>me voy a poner algo más cómodo</text>
                        </translation>
                      </translations>
                    </example>
                    <example>
                      <text>I'm going upstairs to change</text>
                      <translations>
                        <translation>
                          <language>es</language>
                          <text>voy arriba a cambiarme</text>
                        </translation>
                      </translations>
                    </example>
                  </examples>
                  <id>b-en-es0008145.048-se1-3</id>
                  <translations>
                    <translation>
                      <language>es</language>
                      <text>cambiarse</text>
                    </translation>
                  </translations>
                </sense>
                <sense>
                  <domains>
                    <domain>Transport</domain>
                  </domains>
                  <examples>
                    <example>
                      <text>we have to change at Victoria</text>
                      <translations>
                        <translation>
                          <language>es</language>
                          <text>tenemos que cambiar / hacer transbordo en Victoria</text>
                        </translation>
                      </translations>
                    </example>
                    <example>
                      <text>all change!</text>
                      <translations>
                        <translation>
                          <language>es</language>
                          <text>¡fin de trayecto!</text>
                        </translation>
                      </translations>
                    </example>
                  </examples>
                  <id>b-en-es0008145.049-se1-3</id>
                  <translations>
                    <translation>
                      <language>es</language>
                      <text>cambiar</text>
                    </translation>
                    <translation>
                      <language>es</language>
                      <text>hacer transbordo</text>
                    </translation>
                  </translations>
                </sense>
              </senses>
            </entry>
            <entry>
              <grammaticalFeatures>
                <grammaticalFeature>
                  <text>Transitive</text>
                  <type>Subcategorization</type>
                </grammaticalFeature>
                <grammaticalFeature>
                  <text>Present</text>
                  <type>Tense</type>
                </grammaticalFeature>
              </grammaticalFeatures>
              <homographNumber>001</homographNumber>
              <senses>
                <sense>
                  <examples>
                    <example>
                      <text>you can't change the way you are</text>
                      <translations>
                        <translation>
                          <language>es</language>
                          <text>uno no cambia</text>
                        </translation>
                        <translation>
                          <language>es</language>
                          <text>no se puede cambiar la manera de ser</text>
                        </translation>
                      </translations>
                    </example>
                    <example>
                      <text>the sorcerer changed her into a stone</text>
                      <translations>
                        <translation>
                          <language>es</language>
                          <text>el mago la convirtió en una piedra</text>
                        </translation>
                      </translations>
                    </example>
                  </examples>
                  <id>b-en-es0008145.034-se1-2</id>
                  <translations>
                    <translation>
                      <language>es</language>
                      <text>cambiar</text>
                    </translation>
                  </translations>
                </sense>
                <sense>
                  <examples>
                    <example>
                      <text>to change gear</text>
                      <translations>
                        <translation>
                          <language>es</language>
                          <text>hacer el cambio</text>
                        </translation>
                        <translation>
                          <language>es</language>
                          <text>cambiar de marcha</text>
                        </translation>
                      </translations>
                    </example>
                    <example>
                      <text>let's change the subject</text>
                      <translations>
                        <translation>
                          <language>es</language>
                          <text>cambiemos de tema</text>
                        </translation>
                      </translations>
                    </example>
                    <example>
                      <text>to change one's address/job/doctor</text>
                      <translations>
                        <translation>
                          <language>es</language>
                          <text>cambiar de dirección/trabajo/médico</text>
                        </translation>
                      </translations>
                    </example>
                    <example>
                      <text>I've changed jobs</text>
                      <translations>
                        <translation>
                          <language>es</language>
                          <text>he cambiado de trabajo</text>
                        </translation>
                      </translations>
                    </example>
                    <example>
                      <text>she changed her name from Bronowski to Brown</text>
                      <translations>
                        <translation>
                          <language>es</language>
                          <text>se cambió el apellido de Bronowski a Brown</text>
                        </translation>
                      </translations>
                    </example>
                    <example>
                      <text>the time/date of the concert has been changed</text>
                      <translations>
                        <translation>
                          <language>es</language>
                          <text>han cambiado la hora/fecha del concierto</text>
                        </translation>
                      </translations>
                    </example>
                    <example>
                      <text>to change position/direction/color</text>
                      <translations>
                        <translation>
                          <language>es</language>
                          <text>cambiar de posición/dirección/color</text>
                        </translation>
                      </translations>
                    </example>
                  </examples>
                  <id>b-en-es0008145.035-se1-2</id>
                  <translations>
                    <translation>
                      <language>es</language>
                      <text>cambiar</text>
                    </translation>
                  </translations>
                </sense>
                <sense>
                  <examples>
                    <example>
                      <text>if he doesn't like it can I change it?</text>
                      <translations>
                        <translation>
                          <language>es</language>
                          <text>si no le gusta ¿puedo cambiarlo?</text>
                        </translation>
                      </translations>
                    </example>
                    <example>
                      <text>he changed it for a red one</text>
                      <translations>
                        <translation>
                          <language>es</language>
                          <text>lo cambió por uno rojo</text>
                        </translation>
                      </translations>
                    </example>
                    <example>
                      <text>I wouldn't want to change places with her</text>
                      <translations>
                        <translation>
                          <language>es</language>
                          <text>no quisiera estar / verme en su lugar</text>
                        </translation>
                      </translations>
                    </example>
                  </examples>
                  <id>b-en-es0008145.036-se1-2</id>
                  <translations>
                    <translation>
                      <language>es</language>
                      <text>cambiar(se) de</text>
                    </translation>
                  </translations>
                </sense>
                <sense>
                  <examples>
                    <example>
                      <text>can anyone change $20?</text>
                      <translations>
                        <translation>
                          <language>es</language>
                          <text>¿alguien me puede cambiar 20 dólares?</text>
                        </translation>
                      </translations>
                    </example>
                  </examples>
                  <id>b-en-es0008145.038-se1-2</id>
                  <translations>
                    <translation>
                      <language>es</language>
                      <text>cambiar</text>
                    </translation>
                  </translations>
                </sense>
                <sense>
                  <examples>
                    <example>
                      <text>to change dollars into pesos</text>
                      <translations>
                        <translation>
                          <language>es</language>
                          <regions>
                            <region>Spain</region>
                          </regions>
                          <text>cambiar dólares en pesos</text>
                        </translation>
                        <translation>
                          <language>es</language>
                          <text>cambiar dólares a pesos</text>
                        </translation>
                      </translations>
                    </example>
                    <example>
                      <text>to change sth ( into sth)</text>
                      <translations>
                        <translation>
                          <language>es</language>
                          <text>cambiar algo ( a algo)</text>
                        </translation>
                      </translations>
                    </example>
                  </examples>
                  <id>b-en-es0008145.039-se1-2</id>
                  <translations>
                    <translation>
                      <language>es</language>
                      <text>cambiar</text>
                    </translation>
                    <translation>
                      <language>es</language>
                      <text>cambiar algo ( en algo)</text>
                    </translation>
                  </translations>
                </sense>
                <sense>
                  <examples>
                    <example>
                      <text>to change one's clothes/shoes</text>
                      <translations>
                        <translation>
                          <language>es</language>
                          <text>cambiarse de ropa/de zapatos</text>
                        </translation>
                      </translations>
                    </example>
                  </examples>
                  <id>b-en-es0008145.040-se1-2</id>
                  <translations>
                    <translation>
                      <language>es</language>
                      <text>cambiar</text>
                    </translation>
                  </translations>
                </sense>
                <sense>
                  <domains>
                    <domain>Transport</domain>
                  </domains>
                  <examples>
                    <example>
                      <text>you have to change train(s) at Nice</text>
                      <translations>
                        <translation>
                          <language>es</language>
                          <text>tienes que hacer transbordo / cambiar (de trenes) en Niza</text>
                        </translation>
                      </translations>
                    </example>
                  </examples>
                  <id>b-en-es0008145.041-se1-2</id>
                </sense>
              </senses>
            </entry>
          </entries>
        </lexicalEntry>
        <lexicalEntry>
          <language>en</language>
          <lexicalCategory>Noun</lexicalCategory>
          <text>change</text>
          <entries>
            <entry>
              <grammaticalFeatures>
                <grammaticalFeature>
                  <text>Singular</text>
                  <type>Number</type>
                </grammaticalFeature>
              </grammaticalFeatures>
              <homographNumber>000</homographNumber>
              <senses>
                <sense>
                  <id>b-en-es0008145.002</id>
                  <subsenses>
                    <subsense>
                      <examples>
                        <example>
                          <text>there's been a change in the weather</text>
                          <translations>
                            <translation>
                              <language>es</language>
                              <text>ha cambiado el tiempo</text>
                            </translation>
                          </translations>
                        </example>
                        <example>
                          <text>a change for the better</text>
                          <translations>
                            <translation>
                              <language>es</language>
                              <text>un cambio positivo / para mejor</text>
                            </translation>
                          </translations>
                        </example>
                        <example>
                          <text>there has been little change in the last 20 years</text>
                          <translations>
                            <translation>
                              <language>es</language>
                              <text>ha habido pocos cambios en los últimos 20 años</text>
                            </translation>
                          </translations>
                        </example>
                        <example>
                          <text>a change in temperature</text>
                          <translations>
                            <translation>
                              <language>es</language>
                              <text>un cambio de temperatura</text>
                            </translation>
                          </translations>
                        </example>
                        <example>
                          <text>to make changes to sth</text>
                          <translations>
                            <translation>
                              <language>es</language>
                              <text>hacerle cambios a algo</text>
                            </translation>
                          </translations>
                        </example>
                        <example>
                          <text>a change in public opinion/the law</text>
                          <translations>
                            <translation>
                              <language>es</language>
                              <text>un cambio en la opinión pública/la ley</text>
                            </translation>
                          </translations>
                        </example>
                        <example>
                          <text>the change (of life)</text>
                          <translations>
                            <translation>
                              <language>es</language>
                              <text>la menopausia</text>
                            </translation>
                          </translations>
                        </example>
                        <example>
                          <text>a period of great change</text>
                          <translations>
                            <translation>
                              <language>es</language>
                              <text>un período de grandes cambios</text>
                            </translation>
                          </translations>
                        </example>
                        <example>
                          <text>a change for the worse</text>
                          <translations>
                            <translation>
                              <language>es</language>
                              <text>un cambio para peor</text>
                            </translation>
                            <translation>
                              <language>es</language>
                              <text>un cambio para mal</text>
                            </translation>
                          </translations>
                        </example>
                      </examples>
                      <id>b-en-es0008145.003</id>
                      <translations>
                        <translation>
                          <language>es</language>
                          <text>cambio</text>
                        </translation>
                      </translations>
                    </subsense>
                    <subsense>
                      <examples>
                        <example>
                          <text>a change of address/plan/government</text>
                          <translations>
                            <translation>
                              <language>es</language>
                              <text>un cambio de dirección/plan/gobierno</text>
                            </translation>
                          </translations>
                        </example>
                        <example>
                          <text>a change of air/scenery will do you good</text>
                          <translations>
                            <translation>
                              <language>es</language>
                              <text>un cambio de aire(s) / de ambiente te sentará bien</text>
                            </translation>
                          </translations>
                        </example>
                        <example>
                          <text>to have a change of heart</text>
                          <translations>
                            <translation>
                              <language>es</language>
                              <text>cambiar de idea</text>
                            </translation>
                          </translations>
                        </example>
                        <example>
                          <text>an oil/wheel change</text>
                          <translations>
                            <translation>
                              <language>es</language>
                              <text>un cambio de aceite/rueda</text>
                            </translation>
                          </translations>
                        </example>
                      </examples>
                      <id>b-en-es0008145.004</id>
                      <translations>
                        <translation>
                          <language>es</language>
                          <text>cambio</text>
                        </translation>
                      </translations>
                    </subsense>
                    <subsense>
                      <examples>
                        <example>
                          <text>bring at least one change of clothes/underwear</text>
                          <translations>
                            <translation>
                              <language>es</language>
                              <text>tráete al menos una muda (de ropa)/de ropa interior</text>
                            </translation>
                          </translations>
                        </example>
                      </examples>
                      <id>b-en-es0008145.005</id>
                      <translations>
                        <translation>
                          <language>es</language>
                          <text>muda</text>
                        </translation>
                      </translations>
                    </subsense>
                    <subsense>
                      <examples>
                        <example>
                          <text>I'll have coffee for a change</text>
                          <translations>
                            <translation>
                              <language>es</language>
                              <text>para variar tomaré café</text>
                            </translation>
                          </translations>
                        </example>
                        <example>
                          <text>at least it's / it makes a change from chicken</text>
                          <translations>
                            <translation>
                              <language>es</language>
                              <text>por lo menos no es pollo</text>
                            </translation>
                          </translations>
                        </example>
                        <example>
                          <text>he was late, for a change</text>
                          <translations>
                            <translation>
                              <language>es</language>
                              <registers>
                                <register>ironic</register>
                              </registers>
                              <text>llegó tarde para variar</text>
                            </translation>
                          </translations>
                        </example>
                        <example>
                          <text>going abroad would be / make a nice change</text>
                          <translations>
                            <translation>
                              <language>es</language>
                              <text>no estaría mal ir al extranjero para variar</text>
                            </translation>
                          </translations>
                        </example>
                        <example>
                          <text>to ring the changes</text>
                          <translations>
                            <translation>
                              <language>es</language>
                              <text>introducir variaciones</text>
                            </translation>
                          </translations>
                        </example>
                        <example>
                          <text>for a change</text>
                          <translations>
                            <translation>
                              <language>es</language>
                              <registers>
                                <register>ironic</register>
                              </registers>
                              <text>para variar</text>
                            </translation>
                          </translations>
                        </example>
                        <example>
                          <text>the chef likes to ring the changes on the menu every week</text>
                          <translations>
                            <translation>
                              <language>es</language>
                              <text>al chef le gusta variar / cambiar el menú todas las semanas</text>
                            </translation>
                          </translations>
                        </example>
                        <example>
                          <text>a change is as good as a rest</text>
                          <translations>
                            <translation>
                              <language>es</language>
                              <text>con un cambio de actividad se renuevan las energías</text>
                            </translation>
                          </translations>
                        </example>
                      </examples>
                      <id>b-en-es0008145.006</id>
                      <translations>
                        <translation>
                          <language>es</language>
                          <text>cambio</text>
                        </translation>
                      </translations>
                    </subsense>
                  </subsenses>
                </sense>
                <sense>
                  <id>b-en-es0008145.007</id>
                  <subsenses>
                    <subsense>
                      <examples>
                        <example>
                          <text>can you give me some change for the machine?</text>
                          <translations>
                            <translation>
                              <language>es</language>
                              <text>¿me das cambio / monedas para la máquina?</text>
                            </translation>
                          </translations>
                        </example>
                        <example>
                          <text>I can give change for / of $5</text>
                          <translations>
                            <translation>
                              <language>es</language>
                              <text>te puedo cambiar 5 dólares</text>
                            </translation>
                          </translations>
                        </example>
                        <example>
                          <text>I don't have any loose change</text>
                          <translations>
                            <translation>
                              <language>es</language>
                              <text>no tengo dinero suelto</text>
                            </translation>
                          </translations>
                        </example>
                        <example>
                          <text>one dollar in change</text>
                          <translations>
                            <translation>
                              <language>es</language>
                              <text>un dólar en monedas</text>
                            </translation>
                          </translations>
                        </example>
                      </examples>
                      <id>b-en-es0008145.008</id>
                      <translations>
                        <translation>
                          <language>es</language>
                          <text>cambio</text>
                        </translation>
                        <translation>
                          <language>es</language>
                          <text>monedas</text>
                        </translation>
                        <translation>
                          <language>es</language>
                          <text>sencillo</text>
                        </translation>
                        <translation>
                          <language>es</language>
                          <text>feria</text>
                        </translation>
                        <translation>
                          <language>es</language>
                          <text>menudo</text>
                        </translation>
                      </translations>
                    </subsense>
                    <subsense>
                      <examples>
                        <example>
                          <text>keep the change</text>
                          <translations>
                            <translation>
                              <language>es</language>
                              <text>quédese (con) el cambio</text>
                            </translation>
                            <translation>
                              <language>es</language>
                              <text>quédese con el cambio (/ vuelto etc. )</text>
                            </translation>
                          </translations>
                        </example>
                        <example>
                          <text>you can eat well and still have/get change from $10</text>
                          <translations>
                            <translation>
                              <language>es</language>
                              <text>se puede comer bien por menos de 10 dólares</text>
                            </translation>
                          </translations>
                        </example>
                        <example>
                          <text>we didn't get much change out of her</text>
                          <translations>
                            <translation>
                              <language>es</language>
                              <registers>
                                <register>informal</register>
                              </registers>
                              <text>no pudimos sacarle mucho</text>
                            </translation>
                          </translations>
                        </example>
                        <example>
                          <text>not to get much change out of sb</text>
                        </example>
                        <example>
                          <text>you won't get much change from / out of $1,000</text>
                          <translations>
                            <translation>
                              <language>es</language>
                              <text>no te costará mucho menos de 1.000 dólares</text>
                            </translation>
                          </translations>
                        </example>
                        <example>
                          <text>sixty pence change</text>
                          <translations>
                            <translation>
                              <language>es</language>
                              <text>sesenta peniques de cambio (/ vuelto etc. )</text>
                            </translation>
                          </translations>
                        </example>
                      </examples>
                      <id>b-en-es0008145.009</id>
                      <translations>
                        <translation>
                          <language>es</language>
                          <text>cambio</text>
                        </translation>
                        <translation>
                          <language>es</language>
                          <text>vuelto</text>
                        </translation>
                        <translation>
                          <language>es</language>
                          <text>vuelta</text>
                        </translation>
                        <translation>
                          <language>es</language>
                          <text>vueltas</text>
                        </translation>
                      </translations>
                    </subsense>
                  </subsenses>
                </sense>
              </senses>
            </entry>
          </entries>
        </lexicalEntry>
      </lexicalEntries>
    </result>
  </results>
</translation>

I’ve preserved the original structure of the JSON response as much as possible, and have made minimal alterations beyond those descibed in the below section “Translation library module”. One change is returning <translation> as the root XML element, which has the attibutes input and language. The input attribute is assigned a value matching the ‘word’ sent to the Oxford Dictionaries API, and is equivalent to the API’s word_id parameter. Likewise, the language and target-language attributes are assigned values equivalent to the API’s source_lang and target_lang parameters respectively. As a result, <translation input="change" language="en" target-language="es"> allows us to create efficient XML queries on cached English-Spanish translation data related to the string ‘change’. Another addition is a <date> element within the <metadata> element. Text content within <date> is from the response header received from the Oxford Dictionaries API. This is useful for evaluating whether or not to update cached translation data by making a new request for a given word_id to the Oxford Dictionaries API.

Translation library module

The translation module od-api-basex.xquery contains XQuery functions related to translation data, and can be used with the XQuery code below:

import module namespace od-api="od-api-basex" at "https://raw.githubusercontent.com/AdamSteffanick/od-api-xquery/master/od-api-basex.xquery";

Using this library module helps create clean, verbose XML structures that follow the models found in the “Translation” section of the Oxford Dictionaries API documentation. Consider that lexical entry data have the following JSON model schema:

{
  "lexicalEntries": [
    {
      "entries": [
        {
          "etymologies": [
            "string"
          ],
          "grammaticalFeatures": [
            {
              "text": "string",
              "type": "string"
            }
          ],
          "homographNumber": "string",
          "pronunciations": [
            {
              "audioFile": "string",
              "dialects": [
                "string"
              ],
              "phoneticNotation": "string",
              "phoneticSpelling": "string",
              "regions": [
                "string"
              ]
            }
          ],
          "senses": [
            {
              "crossReferenceMarkers": [
                "string"
              ],
              "crossReferences": [
                {
                  "id": "string",
                  "text": "string",
                  "type": "string"
                }
              ],
              "definitions": [
                "string"
              ],
              "domains": [
                "string"
              ],
              "examples": [
                {
                  "definitions": [
                    "string"
                  ],
                  "domains": [
                    "string"
                  ],
                  "regions": [
                    "string"
                  ],
                  "registers": [
                    "string"
                  ],
                  "senseIds": [
                    "string"
                  ],
                  "text": "string",
                  "translations": [
                    {
                      "domains": [
                        "string"
                      ],
                      "grammaticalFeatures": [
                        {
                          "text": "string",
                          "type": "string"
                        }
                      ],
                      "language": "string",
                      "regions": [
                        "string"
                      ],
                      "registers": [
                        "string"
                      ],
                      "text": "string"
                    }
                  ]
                }
              ],
              "id": "string",
              "pronunciations": [
                {
                  "audioFile": "string",
                  "dialects": [
                    "string"
                  ],
                  "phoneticNotation": "string",
                  "phoneticSpelling": "string",
                  "regions": [
                    "string"
                  ]
                }
              ],
              "regions": [
                "string"
              ],
              "registers": [
                "string"
              ],
              "subsenses": [
                {}
              ],
              "translations": [
                {
                  "domains": [
                    "string"
                  ],
                  "grammaticalFeatures": [
                    {
                      "text": "string",
                      "type": "string"
                    }
                  ],
                  "language": "string",
                  "regions": [
                    "string"
                  ],
                  "registers": [
                    "string"
                  ],
                  "text": "string"
                }
              ],
              "variantForms": [
                {
                  "regions": [
                    "string"
                  ],
                  "text": "string"
                }
              ]
            }
          ],
          "variantForms": [
            {
              "regions": [
                "string"
              ],
              "text": "string"
            }
          ]
        }
      ],
      "grammaticalFeatures": [
        {
          "text": "string",
          "type": "string"
        }
      ],
      "language": "string",
      "lexicalCategory": "string",
      "pronunciations": [
        {
          "audioFile": "string",
          "dialects": [
            "string"
          ],
          "phoneticNotation": "string",
          "phoneticSpelling": "string",
          "regions": [
            "string"
          ]
        }
      ],
      "text": "string",
      "variantForms": [
        {
          "regions": [
            "string"
          ],
          "text": "string"
        }
      ]
    }
  ]
}

Requesting translation data for the word ‘change’ returns a JSON response including:

{
  "lexicalEntries": [
    {
      "entries": [
        {
          "grammaticalFeatures": [
            {
              "text": "Intransitive",
              "type": "Subcategorization"
            },
            {
              "text": "Present",
              "type": "Tense"
            }
          ],
          "homographNumber": "002",
          "senses": [
            {
              "examples": [
                {
                  "text": "she's a changed person since she met him",
                  "translations": [
                    {
                      "language": "es",
                      "text": "desde que lo conoció es otra"
                    }
                  ]
                },
                {
                  "text": "I can't believe how much she's changed",
                  "translations": [
                    {
                      "language": "es",
                      "text": "me parece increíble lo mucho que ha cambiado"
                    }
                  ]
                },
                {
                  "text": "to change in shape/size",
                  "translations": [
                    {
                      "language": "es",
                      "text": "cambiar de forma/tamaño"
                    }
                  ]
                },
                {
                  "text": "to change into sth",
                  "translations": [
                    {
                      "language": "es",
                      "text": "convertirse / transformarse en algo"
                    }
                  ]
                },
                {
                  "text": "customs have changed",
                  "translations": [
                    {
                      "language": "es",
                      "text": "las costumbres han cambiado"
                    }
                  ]
                }
              ],
              "id": "b-en-es0008145.044-se1-3",
              "translations": [
                {
                  "language": "es",
                  "text": "cambiar"
                }
              ]
            },
            {
              "examples": [
                {
                  "text": "I've changed to a new dentist",
                  "translations": [
                    {
                      "language": "es",
                      "text": "he cambiado de dentista"
                    }
                  ]
                },
                {
                  "text": "the scene changes to wartime Rome",
                  "translations": [
                    {
                      "language": "es",
                      "text": "la escena pasa / se traslada a Roma durante la guerra"
                    }
                  ]
                },
                {
                  "text": "the cast changes every three months",
                  "translations": [
                    {
                      "language": "es",
                      "text": "el reparto cambia cada tres meses"
                    }
                  ]
                },
                {
                  "text": "her smile changed to a frown",
                  "translations": [
                    {
                      "language": "es",
                      "text": "dejó de sonreír y frunció el ceño"
                    }
                  ]
                },
                {
                  "text": "the traffic lights changed",
                  "translations": [
                    {
                      "language": "es",
                      "text": "cambió el semáforo"
                    },
                    {
                      "language": "es",
                      "text": "cambiaron las luces (del semáforo)"
                    }
                  ]
                }
              ],
              "id": "b-en-es0008145.045-se1-3",
              "translations": [
                {
                  "language": "es",
                  "text": "cambiar"
                }
              ]
            },
            {
              "id": "b-en-es0008145.046-se1-3",
              "translations": [
                {
                  "language": "es",
                  "text": "cambiante"
                }
              ]
            },
            {
              "examples": [
                {
                  "text": "change out of those wet clothes",
                  "translations": [
                    {
                      "language": "es",
                      "text": "quítate esa ropa mojada"
                    }
                  ]
                },
                {
                  "text": "to get changed",
                  "translations": [
                    {
                      "language": "es",
                      "text": "cambiarse"
                    }
                  ]
                },
                {
                  "text": "she changed into a black dress",
                  "translations": [
                    {
                      "language": "es",
                      "text": "se cambió y se puso un vestido negro"
                    }
                  ]
                },
                {
                  "text": "I'm going to change into something more comfortable",
                  "translations": [
                    {
                      "language": "es",
                      "text": "me voy a poner algo más cómodo"
                    }
                  ]
                },
                {
                  "text": "I'm going upstairs to change",
                  "translations": [
                    {
                      "language": "es",
                      "text": "voy arriba a cambiarme"
                    }
                  ]
                }
              ],
              "id": "b-en-es0008145.048-se1-3",
              "translations": [
                {
                  "language": "es",
                  "text": "cambiarse"
                }
              ]
            },
            {
              "domains": [
                "Transport"
              ],
              "examples": [
                {
                  "text": "we have to change at Victoria",
                  "translations": [
                    {
                      "language": "es",
                      "text": "tenemos que cambiar / hacer transbordo en Victoria"
                    }
                  ]
                },
                {
                  "text": "all change!",
                  "translations": [
                    {
                      "language": "es",
                      "text": "¡fin de trayecto!"
                    }
                  ]
                }
              ],
              "id": "b-en-es0008145.049-se1-3",
              "translations": [
                {
                  "language": "es",
                  "text": "cambiar"
                },
                {
                  "language": "es",
                  "text": "hacer transbordo"
                }
              ]
            }
          ]
        },
        {
          "grammaticalFeatures": [
            {
              "text": "Transitive",
              "type": "Subcategorization"
            },
            {
              "text": "Present",
              "type": "Tense"
            }
          ],
          "homographNumber": "001",
          "senses": [
            {
              "examples": [
                {
                  "text": "you can't change the way you are",
                  "translations": [
                    {
                      "language": "es",
                      "text": "uno no cambia"
                    },
                    {
                      "language": "es",
                      "text": "no se puede cambiar la manera de ser"
                    }
                  ]
                },
                {
                  "text": "the sorcerer changed her into a stone",
                  "translations": [
                    {
                      "language": "es",
                      "text": "el mago la convirtió en una piedra"
                    }
                  ]
                }
              ],
              "id": "b-en-es0008145.034-se1-2",
              "translations": [
                {
                  "language": "es",
                  "text": "cambiar"
                }
              ]
            },
            {
              "examples": [
                {
                  "text": "to change gear",
                  "translations": [
                    {
                      "language": "es",
                      "text": "hacer el cambio"
                    },
                    {
                      "language": "es",
                      "text": "cambiar de marcha"
                    }
                  ]
                },
                {
                  "text": "let's change the subject",
                  "translations": [
                    {
                      "language": "es",
                      "text": "cambiemos de tema"
                    }
                  ]
                },
                {
                  "text": "to change one's address/job/doctor",
                  "translations": [
                    {
                      "language": "es",
                      "text": "cambiar de dirección/trabajo/médico"
                    }
                  ]
                },
                {
                  "text": "I've changed jobs",
                  "translations": [
                    {
                      "language": "es",
                      "text": "he cambiado de trabajo"
                    }
                  ]
                },
                {
                  "text": "she changed her name from Bronowski to Brown",
                  "translations": [
                    {
                      "language": "es",
                      "text": "se cambió el apellido de Bronowski a Brown"
                    }
                  ]
                },
                {
                  "text": "the time/date of the concert has been changed",
                  "translations": [
                    {
                      "language": "es",
                      "text": "han cambiado la hora/fecha del concierto"
                    }
                  ]
                },
                {
                  "text": "to change position/direction/color",
                  "translations": [
                    {
                      "language": "es",
                      "text": "cambiar de posición/dirección/color"
                    }
                  ]
                }
              ],
              "id": "b-en-es0008145.035-se1-2",
              "translations": [
                {
                  "language": "es",
                  "text": "cambiar"
                }
              ]
            },
            {
              "examples": [
                {
                  "text": "if he doesn't like it can I change it?",
                  "translations": [
                    {
                      "language": "es",
                      "text": "si no le gusta ¿puedo cambiarlo?"
                    }
                  ]
                },
                {
                  "text": "he changed it for a red one",
                  "translations": [
                    {
                      "language": "es",
                      "text": "lo cambió por uno rojo"
                    }
                  ]
                },
                {
                  "text": "I wouldn't want to change places with her",
                  "translations": [
                    {
                      "language": "es",
                      "text": "no quisiera estar / verme en su lugar"
                    }
                  ]
                }
              ],
              "id": "b-en-es0008145.036-se1-2",
              "translations": [
                {
                  "language": "es",
                  "text": "cambiar(se) de"
                }
              ]
            },
            {
              "examples": [
                {
                  "text": "can anyone change $20?",
                  "translations": [
                    {
                      "language": "es",
                      "text": "¿alguien me puede cambiar 20 dólares?"
                    }
                  ]
                }
              ],
              "id": "b-en-es0008145.038-se1-2",
              "translations": [
                {
                  "language": "es",
                  "text": "cambiar"
                }
              ]
            },
            {
              "examples": [
                {
                  "text": "to change dollars into pesos",
                  "translations": [
                    {
                      "language": "es",
                      "regions": [
                        "Spain"
                      ],
                      "text": "cambiar dólares en pesos"
                    },
                    {
                      "language": "es",
                      "text": "cambiar dólares a pesos"
                    }
                  ]
                },
                {
                  "text": "to change sth ( into sth)",
                  "translations": [
                    {
                      "language": "es",
                      "text": "cambiar algo ( a algo)"
                    }
                  ]
                }
              ],
              "id": "b-en-es0008145.039-se1-2",
              "translations": [
                {
                  "language": "es",
                  "text": "cambiar"
                },
                {
                  "language": "es",
                  "text": "cambiar algo ( en algo)"
                }
              ]
            },
            {
              "examples": [
                {
                  "text": "to change one's clothes/shoes",
                  "translations": [
                    {
                      "language": "es",
                      "text": "cambiarse de ropa/de zapatos"
                    }
                  ]
                }
              ],
              "id": "b-en-es0008145.040-se1-2",
              "translations": [
                {
                  "language": "es",
                  "text": "cambiar"
                }
              ]
            },
            {
              "domains": [
                "Transport"
              ],
              "examples": [
                {
                  "text": "you have to change train(s) at Nice",
                  "translations": [
                    {
                      "language": "es",
                      "text": "tienes que hacer transbordo / cambiar (de trenes) en Niza"
                    }
                  ]
                }
              ],
              "id": "b-en-es0008145.041-se1-2"
            }
          ]
        }
      ],
      "language": "en",
      "lexicalCategory": "Verb",
      "text": "change"
    }
  ]
}

By default, converting the response above from JSON to XML with BaseX yields an undesired XML structure:

<lexicalEntries type="array">
  <_ type="object">
    <entries type="array">
      <_ type="object">
        <grammaticalFeatures type="array">
          <_ type="object">
            <text>Intransitive</text>
            <type>Subcategorization</type>
          </_>
          <_ type="object">
            <text>Present</text>
            <type>Tense</type>
          </_>
        </grammaticalFeatures>
        <homographNumber>002</homographNumber>
        <senses type="array">
          <_ type="object">
            <examples type="array">
              <_ type="object">
                <text>she's a changed person since she met him</text>
                <translations type="array">
                  <_ type="object">
                    <language>es</language>
                    <text>desde que lo conoció es otra</text>
                  </_>
                </translations>
              </_>
              <_ type="object">
                <text>I can't believe how much she's changed</text>
                <translations type="array">
                  <_ type="object">
                    <language>es</language>
                    <text>me parece increíble lo mucho que ha cambiado</text>
                  </_>
                </translations>
              </_>
              <_ type="object">
                <text>to change in shape/size</text>
                <translations type="array">
                  <_ type="object">
                    <language>es</language>
                    <text>cambiar de forma/tamaño</text>
                  </_>
                </translations>
              </_>
              <_ type="object">
                <text>to change into sth</text>
                <translations type="array">
                  <_ type="object">
                    <language>es</language>
                    <text>convertirse / transformarse en algo</text>
                  </_>
                </translations>
              </_>
              <_ type="object">
                <text>customs have changed</text>
                <translations type="array">
                  <_ type="object">
                    <language>es</language>
                    <text>las costumbres han cambiado</text>
                  </_>
                </translations>
              </_>
            </examples>
            <id>b-en-es0008145.044-se1-3</id>
            <translations type="array">
              <_ type="object">
                <language>es</language>
                <text>cambiar</text>
              </_>
            </translations>
          </_>
          <_ type="object">
            <examples type="array">
              <_ type="object">
                <text>I've changed to a new dentist</text>
                <translations type="array">
                  <_ type="object">
                    <language>es</language>
                    <text>he cambiado de dentista</text>
                  </_>
                </translations>
              </_>
              <_ type="object">
                <text>the scene changes to wartime Rome</text>
                <translations type="array">
                  <_ type="object">
                    <language>es</language>
                    <text>la escena pasa / se traslada a Roma durante la guerra</text>
                  </_>
                </translations>
              </_>
              <_ type="object">
                <text>the cast changes every three months</text>
                <translations type="array">
                  <_ type="object">
                    <language>es</language>
                    <text>el reparto cambia cada tres meses</text>
                  </_>
                </translations>
              </_>
              <_ type="object">
                <text>her smile changed to a frown</text>
                <translations type="array">
                  <_ type="object">
                    <language>es</language>
                    <text>dejó de sonreír y frunció el ceño</text>
                  </_>
                </translations>
              </_>
              <_ type="object">
                <text>the traffic lights changed</text>
                <translations type="array">
                  <_ type="object">
                    <language>es</language>
                    <text>cambió el semáforo</text>
                  </_>
                  <_ type="object">
                    <language>es</language>
                    <text>cambiaron las luces (del semáforo)</text>
                  </_>
                </translations>
              </_>
            </examples>
            <id>b-en-es0008145.045-se1-3</id>
            <translations type="array">
              <_ type="object">
                <language>es</language>
                <text>cambiar</text>
              </_>
            </translations>
          </_>
          <_ type="object">
            <id>b-en-es0008145.046-se1-3</id>
            <translations type="array">
              <_ type="object">
                <language>es</language>
                <text>cambiante</text>
              </_>
            </translations>
          </_>
          <_ type="object">
            <examples type="array">
              <_ type="object">
                <text>change out of those wet clothes</text>
                <translations type="array">
                  <_ type="object">
                    <language>es</language>
                    <text>quítate esa ropa mojada</text>
                  </_>
                </translations>
              </_>
              <_ type="object">
                <text>to get changed</text>
                <translations type="array">
                  <_ type="object">
                    <language>es</language>
                    <text>cambiarse</text>
                  </_>
                </translations>
              </_>
              <_ type="object">
                <text>she changed into a black dress</text>
                <translations type="array">
                  <_ type="object">
                    <language>es</language>
                    <text>se cambió y se puso un vestido negro</text>
                  </_>
                </translations>
              </_>
              <_ type="object">
                <text>I'm going to change into something more comfortable</text>
                <translations type="array">
                  <_ type="object">
                    <language>es</language>
                    <text>me voy a poner algo más cómodo</text>
                  </_>
                </translations>
              </_>
              <_ type="object">
                <text>I'm going upstairs to change</text>
                <translations type="array">
                  <_ type="object">
                    <language>es</language>
                    <text>voy arriba a cambiarme</text>
                  </_>
                </translations>
              </_>
            </examples>
            <id>b-en-es0008145.048-se1-3</id>
            <translations type="array">
              <_ type="object">
                <language>es</language>
                <text>cambiarse</text>
              </_>
            </translations>
          </_>
          <_ type="object">
            <domains type="array">
              <_>Transport</_>
            </domains>
            <examples type="array">
              <_ type="object">
                <text>we have to change at Victoria</text>
                <translations type="array">
                  <_ type="object">
                    <language>es</language>
                    <text>tenemos que cambiar / hacer transbordo en Victoria</text>
                  </_>
                </translations>
              </_>
              <_ type="object">
                <text>all change!</text>
                <translations type="array">
                  <_ type="object">
                    <language>es</language>
                    <text>¡fin de trayecto!</text>
                  </_>
                </translations>
              </_>
            </examples>
            <id>b-en-es0008145.049-se1-3</id>
            <translations type="array">
              <_ type="object">
                <language>es</language>
                <text>cambiar</text>
              </_>
              <_ type="object">
                <language>es</language>
                <text>hacer transbordo</text>
              </_>
            </translations>
          </_>
        </senses>
      </_>
      <_ type="object">
        <grammaticalFeatures type="array">
          <_ type="object">
            <text>Transitive</text>
            <type>Subcategorization</type>
          </_>
          <_ type="object">
            <text>Present</text>
            <type>Tense</type>
          </_>
        </grammaticalFeatures>
        <homographNumber>001</homographNumber>
        <senses type="array">
          <_ type="object">
            <examples type="array">
              <_ type="object">
                <text>you can't change the way you are</text>
                <translations type="array">
                  <_ type="object">
                    <language>es</language>
                    <text>uno no cambia</text>
                  </_>
                  <_ type="object">
                    <language>es</language>
                    <text>no se puede cambiar la manera de ser</text>
                  </_>
                </translations>
              </_>
              <_ type="object">
                <text>the sorcerer changed her into a stone</text>
                <translations type="array">
                  <_ type="object">
                    <language>es</language>
                    <text>el mago la convirtió en una piedra</text>
                  </_>
                </translations>
              </_>
            </examples>
            <id>b-en-es0008145.034-se1-2</id>
            <translations type="array">
              <_ type="object">
                <language>es</language>
                <text>cambiar</text>
              </_>
            </translations>
          </_>
          <_ type="object">
            <examples type="array">
              <_ type="object">
                <text>to change gear</text>
                <translations type="array">
                  <_ type="object">
                    <language>es</language>
                    <text>hacer el cambio</text>
                  </_>
                  <_ type="object">
                    <language>es</language>
                    <text>cambiar de marcha</text>
                  </_>
                </translations>
              </_>
              <_ type="object">
                <text>let's change the subject</text>
                <translations type="array">
                  <_ type="object">
                    <language>es</language>
                    <text>cambiemos de tema</text>
                  </_>
                </translations>
              </_>
              <_ type="object">
                <text>to change one's address/job/doctor</text>
                <translations type="array">
                  <_ type="object">
                    <language>es</language>
                    <text>cambiar de dirección/trabajo/médico</text>
                  </_>
                </translations>
              </_>
              <_ type="object">
                <text>I've changed jobs</text>
                <translations type="array">
                  <_ type="object">
                    <language>es</language>
                    <text>he cambiado de trabajo</text>
                  </_>
                </translations>
              </_>
              <_ type="object">
                <text>she changed her name from Bronowski to Brown</text>
                <translations type="array">
                  <_ type="object">
                    <language>es</language>
                    <text>se cambió el apellido de Bronowski a Brown</text>
                  </_>
                </translations>
              </_>
              <_ type="object">
                <text>the time/date of the concert has been changed</text>
                <translations type="array">
                  <_ type="object">
                    <language>es</language>
                    <text>han cambiado la hora/fecha del concierto</text>
                  </_>
                </translations>
              </_>
              <_ type="object">
                <text>to change position/direction/color</text>
                <translations type="array">
                  <_ type="object">
                    <language>es</language>
                    <text>cambiar de posición/dirección/color</text>
                  </_>
                </translations>
              </_>
            </examples>
            <id>b-en-es0008145.035-se1-2</id>
            <translations type="array">
              <_ type="object">
                <language>es</language>
                <text>cambiar</text>
              </_>
            </translations>
          </_>
          <_ type="object">
            <examples type="array">
              <_ type="object">
                <text>if he doesn't like it can I change it?</text>
                <translations type="array">
                  <_ type="object">
                    <language>es</language>
                    <text>si no le gusta ¿puedo cambiarlo?</text>
                  </_>
                </translations>
              </_>
              <_ type="object">
                <text>he changed it for a red one</text>
                <translations type="array">
                  <_ type="object">
                    <language>es</language>
                    <text>lo cambió por uno rojo</text>
                  </_>
                </translations>
              </_>
              <_ type="object">
                <text>I wouldn't want to change places with her</text>
                <translations type="array">
                  <_ type="object">
                    <language>es</language>
                    <text>no quisiera estar / verme en su lugar</text>
                  </_>
                </translations>
              </_>
            </examples>
            <id>b-en-es0008145.036-se1-2</id>
            <translations type="array">
              <_ type="object">
                <language>es</language>
                <text>cambiar(se) de</text>
              </_>
            </translations>
          </_>
          <_ type="object">
            <examples type="array">
              <_ type="object">
                <text>can anyone change $20?</text>
                <translations type="array">
                  <_ type="object">
                    <language>es</language>
                    <text>¿alguien me puede cambiar 20 dólares?</text>
                  </_>
                </translations>
              </_>
            </examples>
            <id>b-en-es0008145.038-se1-2</id>
            <translations type="array">
              <_ type="object">
                <language>es</language>
                <text>cambiar</text>
              </_>
            </translations>
          </_>
          <_ type="object">
            <examples type="array">
              <_ type="object">
                <text>to change dollars into pesos</text>
                <translations type="array">
                  <_ type="object">
                    <language>es</language>
                    <regions type="array">
                      <_>Spain</_>
                    </regions>
                    <text>cambiar dólares en pesos</text>
                  </_>
                  <_ type="object">
                    <language>es</language>
                    <text>cambiar dólares a pesos</text>
                  </_>
                </translations>
              </_>
              <_ type="object">
                <text>to change sth ( into sth)</text>
                <translations type="array">
                  <_ type="object">
                    <language>es</language>
                    <text>cambiar algo ( a algo)</text>
                  </_>
                </translations>
              </_>
            </examples>
            <id>b-en-es0008145.039-se1-2</id>
            <translations type="array">
              <_ type="object">
                <language>es</language>
                <text>cambiar</text>
              </_>
              <_ type="object">
                <language>es</language>
                <text>cambiar algo ( en algo)</text>
              </_>
            </translations>
          </_>
          <_ type="object">
            <examples type="array">
              <_ type="object">
                <text>to change one's clothes/shoes</text>
                <translations type="array">
                  <_ type="object">
                    <language>es</language>
                    <text>cambiarse de ropa/de zapatos</text>
                  </_>
                </translations>
              </_>
            </examples>
            <id>b-en-es0008145.040-se1-2</id>
            <translations type="array">
              <_ type="object">
                <language>es</language>
                <text>cambiar</text>
              </_>
            </translations>
          </_>
          <_ type="object">
            <domains type="array">
              <_>Transport</_>
            </domains>
            <examples type="array">
              <_ type="object">
                <text>you have to change train(s) at Nice</text>
                <translations type="array">
                  <_ type="object">
                    <language>es</language>
                    <text>tienes que hacer transbordo / cambiar (de trenes) en Niza</text>
                  </_>
                </translations>
              </_>
            </examples>
            <id>b-en-es0008145.041-se1-2</id>
          </_>
        </senses>
      </_>
    </entries>
    <language>en</language>
    <lexicalCategory>Verb</lexicalCategory>
    <text>change</text>
  </_>
</lexicalEntries>

We can use XQuery to assign names to the <_> elements above. In the case of elements with plural names, such as <translations>, functions within the library module create child elements with singular names, such as <translation>:

<lexicalEntries>
  <lexicalEntry>
    <language>en</language>
    <lexicalCategory>Verb</lexicalCategory>
    <text>change</text>
    <entries>
      <entry>
        <grammaticalFeatures>
          <grammaticalFeature>
            <text>Intransitive</text>
            <type>Subcategorization</type>
          </grammaticalFeature>
          <grammaticalFeature>
            <text>Present</text>
            <type>Tense</type>
          </grammaticalFeature>
        </grammaticalFeatures>
        <homographNumber>002</homographNumber>
        <senses>
          <sense>
            <examples>
              <example>
                <text>she's a changed person since she met him</text>
                <translations>
                  <translation>
                    <language>es</language>
                    <text>desde que lo conoció es otra</text>
                  </translation>
                </translations>
              </example>
              <example>
                <text>I can't believe how much she's changed</text>
                <translations>
                  <translation>
                    <language>es</language>
                    <text>me parece increíble lo mucho que ha cambiado</text>
                  </translation>
                </translations>
              </example>
              <example>
                <text>to change in shape/size</text>
                <translations>
                  <translation>
                    <language>es</language>
                    <text>cambiar de forma/tamaño</text>
                  </translation>
                </translations>
              </example>
              <example>
                <text>to change into sth</text>
                <translations>
                  <translation>
                    <language>es</language>
                    <text>convertirse / transformarse en algo</text>
                  </translation>
                </translations>
              </example>
              <example>
                <text>customs have changed</text>
                <translations>
                  <translation>
                    <language>es</language>
                    <text>las costumbres han cambiado</text>
                  </translation>
                </translations>
              </example>
            </examples>
            <id>b-en-es0008145.044-se1-3</id>
            <translations>
              <translation>
                <language>es</language>
                <text>cambiar</text>
              </translation>
            </translations>
          </sense>
          <sense>
            <examples>
              <example>
                <text>I've changed to a new dentist</text>
                <translations>
                  <translation>
                    <language>es</language>
                    <text>he cambiado de dentista</text>
                  </translation>
                </translations>
              </example>
              <example>
                <text>the scene changes to wartime Rome</text>
                <translations>
                  <translation>
                    <language>es</language>
                    <text>la escena pasa / se traslada a Roma durante la guerra</text>
                  </translation>
                </translations>
              </example>
              <example>
                <text>the cast changes every three months</text>
                <translations>
                  <translation>
                    <language>es</language>
                    <text>el reparto cambia cada tres meses</text>
                  </translation>
                </translations>
              </example>
              <example>
                <text>her smile changed to a frown</text>
                <translations>
                  <translation>
                    <language>es</language>
                    <text>dejó de sonreír y frunció el ceño</text>
                  </translation>
                </translations>
              </example>
              <example>
                <text>the traffic lights changed</text>
                <translations>
                  <translation>
                    <language>es</language>
                    <text>cambió el semáforo</text>
                  </translation>
                  <translation>
                    <language>es</language>
                    <text>cambiaron las luces (del semáforo)</text>
                  </translation>
                </translations>
              </example>
            </examples>
            <id>b-en-es0008145.045-se1-3</id>
            <translations>
              <translation>
                <language>es</language>
                <text>cambiar</text>
              </translation>
            </translations>
          </sense>
          <sense>
            <id>b-en-es0008145.046-se1-3</id>
            <translations>
              <translation>
                <language>es</language>
                <text>cambiante</text>
              </translation>
            </translations>
          </sense>
          <sense>
            <examples>
              <example>
                <text>change out of those wet clothes</text>
                <translations>
                  <translation>
                    <language>es</language>
                    <text>quítate esa ropa mojada</text>
                  </translation>
                </translations>
              </example>
              <example>
                <text>to get changed</text>
                <translations>
                  <translation>
                    <language>es</language>
                    <text>cambiarse</text>
                  </translation>
                </translations>
              </example>
              <example>
                <text>she changed into a black dress</text>
                <translations>
                  <translation>
                    <language>es</language>
                    <text>se cambió y se puso un vestido negro</text>
                  </translation>
                </translations>
              </example>
              <example>
                <text>I'm going to change into something more comfortable</text>
                <translations>
                  <translation>
                    <language>es</language>
                    <text>me voy a poner algo más cómodo</text>
                  </translation>
                </translations>
              </example>
              <example>
                <text>I'm going upstairs to change</text>
                <translations>
                  <translation>
                    <language>es</language>
                    <text>voy arriba a cambiarme</text>
                  </translation>
                </translations>
              </example>
            </examples>
            <id>b-en-es0008145.048-se1-3</id>
            <translations>
              <translation>
                <language>es</language>
                <text>cambiarse</text>
              </translation>
            </translations>
          </sense>
          <sense>
            <domains>
              <domain>Transport</domain>
            </domains>
            <examples>
              <example>
                <text>we have to change at Victoria</text>
                <translations>
                  <translation>
                    <language>es</language>
                    <text>tenemos que cambiar / hacer transbordo en Victoria</text>
                  </translation>
                </translations>
              </example>
              <example>
                <text>all change!</text>
                <translations>
                  <translation>
                    <language>es</language>
                    <text>¡fin de trayecto!</text>
                  </translation>
                </translations>
              </example>
            </examples>
            <id>b-en-es0008145.049-se1-3</id>
            <translations>
              <translation>
                <language>es</language>
                <text>cambiar</text>
              </translation>
              <translation>
                <language>es</language>
                <text>hacer transbordo</text>
              </translation>
            </translations>
          </sense>
        </senses>
      </entry>
      <entry>
        <grammaticalFeatures>
          <grammaticalFeature>
            <text>Transitive</text>
            <type>Subcategorization</type>
          </grammaticalFeature>
          <grammaticalFeature>
            <text>Present</text>
            <type>Tense</type>
          </grammaticalFeature>
        </grammaticalFeatures>
        <homographNumber>001</homographNumber>
        <senses>
          <sense>
            <examples>
              <example>
                <text>you can't change the way you are</text>
                <translations>
                  <translation>
                    <language>es</language>
                    <text>uno no cambia</text>
                  </translation>
                  <translation>
                    <language>es</language>
                    <text>no se puede cambiar la manera de ser</text>
                  </translation>
                </translations>
              </example>
              <example>
                <text>the sorcerer changed her into a stone</text>
                <translations>
                  <translation>
                    <language>es</language>
                    <text>el mago la convirtió en una piedra</text>
                  </translation>
                </translations>
              </example>
            </examples>
            <id>b-en-es0008145.034-se1-2</id>
            <translations>
              <translation>
                <language>es</language>
                <text>cambiar</text>
              </translation>
            </translations>
          </sense>
          <sense>
            <examples>
              <example>
                <text>to change gear</text>
                <translations>
                  <translation>
                    <language>es</language>
                    <text>hacer el cambio</text>
                  </translation>
                  <translation>
                    <language>es</language>
                    <text>cambiar de marcha</text>
                  </translation>
                </translations>
              </example>
              <example>
                <text>let's change the subject</text>
                <translations>
                  <translation>
                    <language>es</language>
                    <text>cambiemos de tema</text>
                  </translation>
                </translations>
              </example>
              <example>
                <text>to change one's address/job/doctor</text>
                <translations>
                  <translation>
                    <language>es</language>
                    <text>cambiar de dirección/trabajo/médico</text>
                  </translation>
                </translations>
              </example>
              <example>
                <text>I've changed jobs</text>
                <translations>
                  <translation>
                    <language>es</language>
                    <text>he cambiado de trabajo</text>
                  </translation>
                </translations>
              </example>
              <example>
                <text>she changed her name from Bronowski to Brown</text>
                <translations>
                  <translation>
                    <language>es</language>
                    <text>se cambió el apellido de Bronowski a Brown</text>
                  </translation>
                </translations>
              </example>
              <example>
                <text>the time/date of the concert has been changed</text>
                <translations>
                  <translation>
                    <language>es</language>
                    <text>han cambiado la hora/fecha del concierto</text>
                  </translation>
                </translations>
              </example>
              <example>
                <text>to change position/direction/color</text>
                <translations>
                  <translation>
                    <language>es</language>
                    <text>cambiar de posición/dirección/color</text>
                  </translation>
                </translations>
              </example>
            </examples>
            <id>b-en-es0008145.035-se1-2</id>
            <translations>
              <translation>
                <language>es</language>
                <text>cambiar</text>
              </translation>
            </translations>
          </sense>
          <sense>
            <examples>
              <example>
                <text>if he doesn't like it can I change it?</text>
                <translations>
                  <translation>
                    <language>es</language>
                    <text>si no le gusta ¿puedo cambiarlo?</text>
                  </translation>
                </translations>
              </example>
              <example>
                <text>he changed it for a red one</text>
                <translations>
                  <translation>
                    <language>es</language>
                    <text>lo cambió por uno rojo</text>
                  </translation>
                </translations>
              </example>
              <example>
                <text>I wouldn't want to change places with her</text>
                <translations>
                  <translation>
                    <language>es</language>
                    <text>no quisiera estar / verme en su lugar</text>
                  </translation>
                </translations>
              </example>
            </examples>
            <id>b-en-es0008145.036-se1-2</id>
            <translations>
              <translation>
                <language>es</language>
                <text>cambiar(se) de</text>
              </translation>
            </translations>
          </sense>
          <sense>
            <examples>
              <example>
                <text>can anyone change $20?</text>
                <translations>
                  <translation>
                    <language>es</language>
                    <text>¿alguien me puede cambiar 20 dólares?</text>
                  </translation>
                </translations>
              </example>
            </examples>
            <id>b-en-es0008145.038-se1-2</id>
            <translations>
              <translation>
                <language>es</language>
                <text>cambiar</text>
              </translation>
            </translations>
          </sense>
          <sense>
            <examples>
              <example>
                <text>to change dollars into pesos</text>
                <translations>
                  <translation>
                    <language>es</language>
                    <regions>
                      <region>Spain</region>
                    </regions>
                    <text>cambiar dólares en pesos</text>
                  </translation>
                  <translation>
                    <language>es</language>
                    <text>cambiar dólares a pesos</text>
                  </translation>
                </translations>
              </example>
              <example>
                <text>to change sth ( into sth)</text>
                <translations>
                  <translation>
                    <language>es</language>
                    <text>cambiar algo ( a algo)</text>
                  </translation>
                </translations>
              </example>
            </examples>
            <id>b-en-es0008145.039-se1-2</id>
            <translations>
              <translation>
                <language>es</language>
                <text>cambiar</text>
              </translation>
              <translation>
                <language>es</language>
                <text>cambiar algo ( en algo)</text>
              </translation>
            </translations>
          </sense>
          <sense>
            <examples>
              <example>
                <text>to change one's clothes/shoes</text>
                <translations>
                  <translation>
                    <language>es</language>
                    <text>cambiarse de ropa/de zapatos</text>
                  </translation>
                </translations>
              </example>
            </examples>
            <id>b-en-es0008145.040-se1-2</id>
            <translations>
              <translation>
                <language>es</language>
                <text>cambiar</text>
              </translation>
            </translations>
          </sense>
          <sense>
            <domains>
              <domain>Transport</domain>
            </domains>
            <examples>
              <example>
                <text>you have to change train(s) at Nice</text>
                <translations>
                  <translation>
                    <language>es</language>
                    <text>tienes que hacer transbordo / cambiar (de trenes) en Niza</text>
                  </translation>
                </translations>
              </example>
            </examples>
            <id>b-en-es0008145.041-se1-2</id>
          </sense>
        </senses>
      </entry>
    </entries>
  </lexicalEntry>
</lexicalEntries>

The majority of the XQuery code in the library module od-api-basex.xquery is not specific to BaseX, however I did use the BaseX HTTP Module. Changes to the library module may be required when using a different XQuery processor.

What we learned

Thanks to this session of the Vanderbilt University XQuery Working Group, we can now:

Thank you for reading, and have fun coding.