xml - 如何使用 Xquery 向元素节点插入多个属性?
问题描述
如何为每个单独的写入器赋予不同的属性,以便下面的示例之一具有多个写入属性节点?
所需的输出:
<writers writer="n"></writers>
<writers writer="a";writer="b";writer="c"></writers>
<writers writer="z"></writers>
xml
(正如评论和答案中指出的那样无效。)
输出:
<writers writer="Giada De Laurentiis"></writers>
<writers writer="J K. Rowling"></writers>
<writers writer="James McGovern Per Bothner Kurt Cagle James Linn Vaidyanathan Nagarajan"></writers>
<writers writer="Erik T. Ray"></writers>
询问:
xquery version "3.1";
declare option output:method 'html';
for $doc in db:open("bookstore")
let $books := $doc/bookstore/book
for $book in $books
let $authors := $book/author
return <writers writer="{data($authors)}"></writers>
故意嵌套循环。
解决方案
你可以做的是例如
element { 'writers' } { $authors ! attribute { 'writer' || position() } { . } }
但是,如果元素或属性名称带有索引,通常会被认为是一种非常糟糕的 XML 样式,您不能为此编写 DTDS 或模式,并且 XPath 或 XQuery 选择可能会变得复杂。
推荐阅读
- java - Java JDK 11 的安装不包括 rt.jar
- javascript - Javascript - 打破循环依赖的问题
- python-3.x - 如何处理python中的用户输入错误
- python - 为什么 Netmiko 不使用动态分配的(主机名)IP 地址进行连接?
- reactjs - 获取与给定 ID 不匹配的 Firestore 集合查询中的第一项
- .net-core - 如何在 Linux 上以后台模式执行 dotnet 测试
- python - 如何在发出 n 次请求后重新启动会话
- go - 为什么 O(n^2) 解决方案更快?2020 年代码出现的第 1 天
- python - 如何从网站上的图表中抓取值
- python-2.7 - Python 全局变量在函数中不可用