Recursion 内部标记的XQuery递归函数调用

Recursion 内部标记的XQuery递归函数调用,recursion,xquery,Recursion,Xquery,我试图准备一个XML文件来解析它,它的上下文如下: <user_manual> <embed-language_part id="SL14686180"> <language_part id="1" role="-" lang="de"> <embed-user_manual_part id="1"> <user_manual_part id="1" role="-" document-type="IU

我试图准备一个XML文件来解析它,它的上下文如下:

<user_manual>
  <embed-language_part id="SL14686180">
    <language_part id="1" role="-" lang="de">
      <embed-user_manual_part id="1">
        <user_manual_part id="1" role="-" document-type="IU">
          <embed-chapter id="1">
            <?ecls-start-embedded-resource resource="ecls_bio_becls_a3_a30660983"?>
            <chapter id="1" role="-" toctitle="yes" footrowtitle="no" type="security">
              <embed-title_module id="1">
                <title_module id="1" role="-">
                  <title id="1">Sicherheits- und Warnhinweise</title>
                </title_module>
              </embed-title_module>
              <embed-section id="1">
                <section id="1" footrowtitle="no" role="-" toctitle="yes">
                  <embed-section id="2">
                    <section id="2">
                      <embed-title_module id="2">
                        <title_module id="2" role="-">
                          <title id="2">Eisschale</title>
                        </title_module>
                      </embed-title_module>
                    </section>
                  </embed-section>
                  <embed-title_module id="3">
                    <title_module id="31" role="-">
                      <title id="3">Bevor Sie das Gerat in Betrieb nehmen</title>
                    </title_module>
                  </embed-title_module>
                </section>
              </embed-section>
            </chapter>
          </embed-chapter>
        </user_manual_part>
      </embed-user_manual_part>
    </language_part>
  </embed-language_part>
</user_manual>
这将返回:

<dmContainer>
   <de title="Sicherheits- und Warnhinweise" language="de" name="223333_30660983">
      <section title="Bevor Sie das Gerat in Betrieb nehmen" />
   </de>
</dmContainer>

Return包含JSON的chapter元素及其第一节的标题,但是我必须将这个添加到所有节中(这些节也包含在节中)

根据输入XML,这些部分可以递归地具有其他部分(一个或多个)。您可以通过深入搜索来查看示例。问题是,我如何用适当的递归方式将这些部分添加到我的输出中(我的意思是不只是包含一级二级的子级),我搜索了一些XQuery递归函数的示例,但没有找到任何示例

预期产出:

 <dmContainer>
   <de title="Sicherheits- und Warnhinweise" language="de" name="223333_30660983">
      <section title="Bevor Sie das Gerat in Betrieb nehmen">
      <section title="Eisschale"/>
      </section>
   </de>
</dmContainer>

如何获取所有章节?

如果您只想获取该章节中的所有章节(按文档顺序),请使用
子代或self-step
,缩写为
/

for $section in $embed_chapter/chapter//embed-section/section
    return <section title="{data($section/embed-title_module/title_module/title)}"
用于$embed\u章/章中的$section//embed section/section

返回请看看如何发布一个。如果您希望其他人专门针对您的代码回答您的问题,请确保他们可以通过复制粘贴直接运行代码:无外部变量,什么是
$language
?对XML进行适当的缩进也有助于理解这个问题。其他的是从$doc派生的,$语言也是派生的。那么问题出在哪里呢?看来我没能把所有的东西都整合起来,你是对的。我删除了我的否决票,因为代码经过一些修改后仍然有效。不过,我仍然不认为这是个好问题。为什么要声明外部变量,而不是将内容放在那里?不需要描述要传递给它们的内容(而且这个描述并不正确:似乎
$doc
不应该包含“文档名”,而是文档名)。这是一个需要付出努力的问题,同时也需要去除不必要的部分(如语言和名称属性的整个构造,这与问题无关)。很抱歉我在这一点上犯了错误,感谢您的编辑。
for $section in $embed_chapter/chapter//embed-section/section
    return <section title="{data($section/embed-title_module/title_module/title)}"