XQuery 嵌套 For 循环

2023-12-19

我有一个示例 xml 文件,例如:

<user_manual document-type="IU" ts-cover="Language Part alt" ts-lang="-" ts-multi="Language Part, Chapter" ts-overview="-" metadata1="9211" brand="Bosch" material-number="dummy_9000727237" vib="RW404960" language-codes="de, en" production-date="2012-12-03" layout-type="-" id="SL9761901">
<embed-language_part id="SL14686180">
<language_part id="ecls_bio_becls_a3_a14686169.SL9761756.7" role="-" lang="de">
<embed-user_manual_part id="ecls_bio_becls_a3_a14686169.SL14686446.10">
<?ecls-start-embedded-resource resource="ecls_bio_becls_a3_a17144756"?> 
<user_manual_part id="ecls_bio_becls_a3_a17144756.SL9765760.11" role="-" document-type="IU">
<embed-chapter id="ecls_bio_becls_a3_a17144756.SL9762101.13">
<?ecls-start-embedded-resource resource="ecls_bio_becls_a3_a30660983"?> 
<chapter id="ecls_bio_becls_a3_a30660983.SL2300626.14" role="-" toctitle="yes" footrowtitle="no" type="security">
<embed-title_module id="ecls_bio_becls_a3_a30660983.SL2361816.15">
<?ecls-start-embedded-resource resource="ecls_bio_becls_a3_a611713"?> 
<title_module id="ecls_bio_becls_a3_a611713.SL873735.16" role="-">
<title id="ecls_bio_becls_a3_a611713.SL873736.17">Sicherheits- und Warnhinweise</title> 
</title_module>
<?ecls-end-embedded-resource resource="ecls_bio_becls_a3_a611713"?> 
</embed-title_module>
<embed-section id="ecls_bio_becls_a3_a30660983.SL10400094.18">
<?ecls-start-embedded-resource resource="ecls_bio_becls_a3_a11752692"?>  
<section id="ecls_bio_becls_a3_a11752692.SL1742298.19" footrowtitle="no" role="-" toctitle="yes">
<?Pub Caret1?> 
<embed-title_module id="ecls_bio_becls_a3_a11752692.SL1742291.20">
<?ecls-start-embedded-resource resource="ecls_bio_becls_a3_a16181733"?> 
<title_module id="ecls_bio_becls_a3_a16181733.SL984238.21" role="-">
<title id="ecls_bio_becls_a3_a16181733.SL984239.22">Bevor Sie das Gerat in Betrieb nehmen</title> 
<para id="ecls_bio_becls_a3_a16181733.SL984240.23">Lesen Sie Gebrauchs- und Montageanleitung aufmerksam durch! Sie enthalten wichtige Informationen �ber Aufstellen, Gebrauch und Wartung des Ger�tes.</para> 
<para id="ecls_bio_becls_a3_a16181733.SL984241.24">Der Hersteller haftet nicht, wenn Sie die Hinweise und Warnungen der Gebrauchsanleitung missachten. Bewahren Sie alle Unterlagen f�r sp�teren Gebrauch oder f�r Nachbesitzer auf.</para> 
</title_module>
<?ecls-end-embedded-resource resource="ecls_bio_becls_a3_a16181733"?> 
</embed-title_module>
</section>
<?Pub *0000000275?> 
<?ecls-end-embedded-resource resource="ecls_bio_becls_a3_a11752692"?> 
</embed-section>
</chapter>
</embed-chapter>
</user_manual_part>
</embed-user_manual_part>
</language_part>
</embed-language_part>
</user_manual>

我想使用 XQuery 语言,但我对这种查询语言很陌生。

我需要的基础设施是这样的:我想获取章节及其章节及其标题,例如:

该章节类似于此 xml 文件:

    <chapter id="ecls_bio_becls_a3_a30660983.SL2300626.14" role="-" toctitle="yes" footrowtitle="no" type="security">
    <embed-title_module id="ecls_bio_becls_a3_a30660983.SL2361816.15">
    <?ecls-start-embedded-resource resource="ecls_bio_becls_a3_a611713"?> 
    <title_module id="ecls_bio_becls_a3_a611713.SL873735.16" role="-">
    <title id="ecls_bio_becls_a3_a611713.SL873736.17">Sicherheits- und Warnhinweise</title>
...

在该示例中,Sicherheits-ind Warnhinweise 是章节元素的标题。章节可以有许多部分,在我们的示例中,部分的标题是:

       <section id="ecls_bio_becls_a3_a11752692.SL1742298.19" footrowtitle="no" role="-" toctitle="yes">
        <?Pub Caret1?> 
        <embed-title_module id="ecls_bio_becls_a3_a11752692.SL1742291.20">
        <?ecls-start-embedded-resource resource="ecls_bio_becls_a3_a16181733"?> 
        <title_module id="ecls_bio_becls_a3_a16181733.SL984238.21" role="-">
        <title id="ecls_bio_becls_a3_a16181733.SL984239.22">Bevor Sie das Gerat in Betrieb nehmen</title> 
...

Bevor Sie das Gerät in Betrieb nehmen。

预期结构:

<chapter> title:"Chapter's title"
<section>title:"First section's title"</section>
<section>title:"Second section's title"</section>
</chapter>

对于该示例章节只有一个部分,但我只是配置了这个部分来达到我的文件的解决方案,我想这是最可读的配置......

我尝试了下面的 xquery 查询:

<chapter
    let $doc := doc("Test.xml")
    for $chapter in $doc/user_manual/embed-language_part/language_part/embed-user_manual_part/user_manual_part/embed-chapter/chapter
        let $chapter_title := $chapter/embed-title_module/title_module/title
        for $section in $chapter/embed-section/section
        return <chapter>title:{data($chapter_title)} <section> title:{data($section/embed-title_module/title_module/title)}</section></chapter>

有两个嵌套循环,但这段代码使我的结构如下:

<chapter>title:"Chapter's title"<section>"First section's title"</section></chapter>
<chapter>title:"Chapter's title"<section>"Second section's title"</section></chapter>

问题是循环,但是当我尝试编辑这样的代码时:

let $doc := doc("assemble.xml")
    for $chapter in $doc/user_manual/embed-language_part/language_part/embed-user_manual_part/user_manual_part/embed-chapter/chapter
        let $chapter_title := $chapter/embed-title_module/title_module/title
        <chapter> title:{data($chapter_title)} {
        for $section in $chapter/embed-section/section
        return <section> title:{data($section/embed-title_module/title_module/title)}</section>
        }</chapter>

我只想将标签放在第一个循环中,之后我将添加部分元素进行查询。但上面的命令并没有达到我的预期。

所以我需要你的建议来正确地获得这些结构。先感谢您。我希望我能清楚地告诉大家情况。文件名称假定为“assemble.xml”。


<chapters>{
let $doc := doc("assemble.xml")
for $chapter in $doc/user_manual/embed-language_part/language_part/embed-user_manual_part/user_manual_part/embed-chapter/chapter
return
    <chapter>
    title:{data($chapter/embed-title_module/title_module/title)}
        {
            for $section in $chapter/embed-section/section
                return <section>title: {data($section/embed-title_module/title_module/title)}</section>
        }
    </chapter>
}</chapters>

我在互联网上搜索,找到了如何进行内循环操作。下面的代码完全符合我的期望。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

XQuery 嵌套 For 循环 的相关文章

  • JAXB - 忽略元素

    有什么方法可以忽略 Jaxb 解析中的元素吗 我有一个很大的 XML 文件 如果我可以忽略其中一个大而复杂的元素 那么它的解析速度可能会快很多 如果它根本无法验证元素内容并解析文档的其余部分 即使该元素不正确 那就更好了 例如 这应该只生成
  • 如何使用 Webpack 加载器导入 XML,而不自动转换为 JSON

    Webpack 4 的 xml loader 自动将导入的 XML 文件转换为 JSON 通过什么方式可以导入XMLwithout转换为 JSON XML 数据将使用现有的 应用程序专用的 XML 解析器进行处理 明确地说 我绝对愿意not
  • 将 Access 数据库转换为 SQL Microsoft DTS - 数据类型“130”不在映射文件中

    我正在尝试将大型 Access mdb 数据库导出到 SQL Server 数据库 但遇到了 Microsoft DTS 无法识别 Access 数据库中特定类型字段的数据类型的问题 我查看了相关的访问表 它们被设置为长度为 1 的 文本
  • Java 8:并行 FOR 循环

    我听说 Java 8 提供了很多关于并发计算的实用程序 因此我想知道并行给定 for 循环的最简单方法是什么 public static void main String args Set
  • 将 XML 映射到 C# 中的类

    我希望使用 XmlSerializer 对象将嵌套元素中的多个 XML 属性映射到单个 POCO 类中 XML
  • 将巨大的模式编译成Java

    有两个主要工具提供了将 XSD 模式编译为 Java 的方法 xmlbeans 和 JAXB 问题是 XSD 模式确实很大 30MB 的 XML 文件 大部分模式在我的项目中没有使用 所以我可以注释掉大部分代码 但这不是一个好的解决方案 目
  • 有人可以推荐一个免费的 xslt 工具吗? [关闭]

    就目前情况而言 这个问题不太适合我们的问答形式 我们希望答案得到事实 参考资料或专业知识的支持 但这个问题可能会引发辩论 争论 民意调查或扩展讨论 如果您觉得这个问题可以改进并可能重新开放 访问帮助中心 help reopen questi
  • VBA XML V6.0 如何让它等待页面加载?

    我一直在努力寻找答案 但似乎找不到任何有用的东西 基本上 我是从一个网站上拉取的 当您在该页面上时 该网站会加载更多项目 我希望我的代码在加载完成后提取最终数据 但不知道如何让 XML httprequest 等待 Edited Sub p
  • 解组转义 XML

    在 Go 中 我将如何解码此 XML 响应 我尝试过建立一个自定义UnMarshal方法在我的Answerstruct 但我运气不太好
  • python dicttoxml 多次使用相同的键

    我正在尝试做如下所示的 xml
  • MSMQ接收和删除

    是否有任何选项可以在读取消息后将其从 MSMQ 中删除 比如 接收 删除可以作为原子操作运行吗 听起来您想查看下一条消息 然后在处理完成后接收它 Message message Queue Peek Queue ReceiveById me
  • matlab中无限while嵌套在for循环中

    我想做一个while循环 嵌套在for在 Matlab 中循环以查找数据中不同对之间的距离 我的数据具有以下形式 ID lon lat time 1 33 56 40 89 803 2 32 45 41 03 803 3 35 78 39
  • 使用 GWT 读取非常大的本地 XML 文件

    我正在使用 GWT 构建我的第一个 Java 应用程序 它必须从一个非常大的 XML 文件中读取数据 当我尝试发送对文件中信息的请求时遇到问题 并且我不太确定它是否与文件的大小或我的语义有关 在我的程序中 我有以下内容 static fin
  • 删除Android所有语言中的字符串

    我有一个包含多个翻译的应用程序 我想删除一些字符串 我怎样才能重构并删除它们一次 例如在默认情况下strings xml文件并自动将删除传播到其他翻译的其他 strings xml 文件 您可以通过 Android Studio 中的 翻译
  • 如何在 Spring 属性中进行算术运算?

  • 使用 Jackson 使用不带注释的属性来序列化 xml

    我目前正在使用 Jackson 编写一些代码 将遗留 POJO 序列化为 XML 但我需要使用属性而不是子元素来序列化它们 有没有办法使用 Jackson 来做到这一点 而不需要向遗留类添加注释 有没有办法使用 Jackson 来做到这一点
  • 使用 dpi 与 dp 缩放图像之间的差异

    我拥有所有由九个补丁位图组成的 dpi 可绘制目录 xxhdpi 和 xxxhdpi 是否必要 可绘制目录中的可绘制资源文件可检索所有缩放的位图 并且我使用可绘制资源文件 现在 我的问题是我还根据大小 小 正常等 创建了 缩放 布局目录 其
  • 如何在 R 中的 for 循环内将值存储在向量中

    我正在开始使用 R 但我对以下问题感到非常沮丧 我试图将 for 循环内完成的某些计算的值存储到我之前定义的向量中 问题是如何进行索引 因为for循环迭代代码的次数取决于用户的输入 所以变量i不一定要从1开始 它可以从80开始 for举个例
  • 将 XSD 文件转换为 C# 可序列化类

    我尝试遵循以下答案这个问题 https stackoverflow com questions 87621 how do i map xml to c objects 但无法让 xsd exe 愉快地获取 XSD 文件并将它们转换为类 此处
  • 将 LINQ 嵌套到 XML

    我有一些来自遗留应用程序的非标准 XML

随机推荐