在父元素的上下文中交错两个元素的多个值?

Interleave multiple values from two elements in parent element's context?

我有这样的数据:

<?xml version="1.0" encoding="UTF-8"?>
<colors>
   <color id="ff0000">
      <label language="en">red</label>
      <label language="de">rot</label>
      <label language="es">rojo</label>
   </color>
   <color id="008000">
      <label language="en">green</label>
      <label language="de">gruen</label>
      <label language="es">verde</label>
   </color>
   <color id="0000ff">
      <label language="en">blue</label>
      <label language="de">blau</label>
      <label language="es">azul</label>
   </color>
</colors>

我想把它转换成这样的table

+--------+----------------------------+
| id     | labels                     |
+--------+----------------------------+
| ff0000 | en:red|de:rot|es:rojo      |
+--------+----------------------------+
| 008000 | en:green|de:gruen|es:verde |
+--------+----------------------------+
| 0000ff | en:blue|de:blau|es:azul    |
+--------+----------------------------+

我知道如何连接同一父元素上下文中的多个值,但是我不知道如何为一个元素粘贴属性和数据,然后将这些组合粘贴到父元素中。

declare option output:method "csv";
declare option output:csv "header=yes, separator=tab";

for $color in doc(
  'color_words'
)/colors/color

let $id := data($color/@id)
let $language := fn:normalize-space(string-join($color/label/@language,'|'))
let $label := fn:normalize-space(string-join($color/label,'|'))

return

<csv>
  <record>
    <id>
      {$id}
    </id>
    <language>
      {$language}
    </language>
    <label>
      {$label}
    </label>
  </record>
</csv>
+--------+----------+-------------------+
| id     | language | label             |
+--------+----------+-------------------+
| ff0000 | en|de|es | red|rot|rojo      |
+--------+----------+-------------------+
| 008000 | en|de|es | green|gruen|verde |
+--------+----------+-------------------+
| 0000ff | en|de|es | blue|blau|azul    |
+--------+----------+-------------------+

您可以使用这个 let 表达式:

let $label := fn:normalize-space(string-join($color/label/concat(@language,':',.),'|'))

它将创建所需的输出。另一个 let 表达式不是必需的。