XQuery:使用给定名称创建一个新元素?

发布于 2024-08-27 01:04:08 字数 281 浏览 0 评论 0原文

我有这样的数据:

    <td>USERID</td>

    <td>NAME</td>

    <td>RATING</td>

我想将其转换为:

<userid></userid>
<name></name>
<rating></rating>

我该怎么做?

I have data like:

    <td>USERID</td>

    <td>NAME</td>

    <td>RATING</td>

I want to transform it into:

<userid></userid>
<name></name>
<rating></rating>

How can I do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

和我恋爱吧 2024-09-03 01:04:08

使用计算元素构造函数来为每个 td 元素生成一个具有 text 节点的 小写 值的元素。

计算元素构造函数
创建一个元素节点,允许两者
节点的名称和内容
待计算。

为了举例说明,假设您的 XML 位于名为 foo.xml 的文件中,您可以执行以下操作:

<doc>
{
for $name in doc('foo.xml')//td/text()
return element {lower-case($name)} {''}
}
</doc>

生成以下内容:

<?xml version="1.0" encoding="UTF-8"?>
<doc>
 <userid/>
 <name/>
 <rating/>
</doc>

您还可以计算 lower-case( ) 函数作为 XPATH 表达式的一部分,而不是元素构造函数,如下所示:

<doc>
{
for $name in doc('foo.xml')//td/text()/lower-case(.)
return element {$name} {''}
}
</doc>

Use a computed element constructor to generate an element with the lower-case value of the text nodes for each of the td elements.

A computed element constructor
creates an element node, allowing both
the name and the content of the node
to be computed.

For the sake of the example, assuming that your XML is in a file called foo.xml, you could do something like this:

<doc>
{
for $name in doc('foo.xml')//td/text()
return element {lower-case($name)} {''}
}
</doc>

to produce this:

<?xml version="1.0" encoding="UTF-8"?>
<doc>
 <userid/>
 <name/>
 <rating/>
</doc>

You could also evaluate the lower-case() function as part of the XPATH expression instead of the element constructor, like this:

<doc>
{
for $name in doc('foo.xml')//td/text()/lower-case(.)
return element {$name} {''}
}
</doc>
千紇 2024-09-03 01:04:08
return <doc>{
for $d in $doc/element()/text()
return element{fn:lower-case($d)} {}}</doc>  

其中 $doc 存储 Xml。

return <doc>{
for $d in $doc/element()/text()
return element{fn:lower-case($d)} {}}</doc>  

where $doc stores the Xml.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文