当前位置: 首页 > 网络学院 > XML相关教程 > Xquery > XQuery 添加元素和属性
We will use the "books.xml" document in the examples below (same XML file as in the previous chapters).
下述案例中,我们会用到 "books.xml" 文档(上一章使用的XML文件)。
View the "books.xml" file in your browser.
在你的浏览器中浏览“books.xml”。
As we have seen in a previous chapter, we may include elements and attributes from the input document ("books.xml) in the result:
就像在前几章中所看到的,我们可以把来自输入文档("books.xml)的元素和属性添加到结果中:
for $x in doc("books.xml")/bookstore/book/title |
The XQuery expression above will include both the title element and the lang attribute in the result, like this:
上述 XQuery 表达式会将 title 元素和 lang 属性添加到结果中,如下所示:
<title lang="en">Everyday Italian</title> |
The XQuery expression above returns the title elements the exact same way as they are described in the input document.
上述 XQuery 表达式获取了 title 元素,它们和原来在输入文档中被描述的一样。
We now want to add our own elements and attributes to the result!
现在,我们希望把我们自己的元素和属性添加到结果中。
Now, we want to add some HTML elements to the result. We will put the result in an HTML list - together with some text:
现在,我们希望将一些HTML元素添加到结果中。我们将把结果连同一些文本内容放在一个HTML列表中:
<html> <h1>Bookstore</h1> <ul> </body> |
The XQuery expression above will generate the following result:
上述XQuery表达式将会输出下面的结果:
<html> <h1>Bookstore</h1> <ul> </body> |
Next, we want to use the category attribute as a class attribute in the HTML list:
接下来,我们希望把 category 属性作为 HTML 列表的一个类属性:
<html> <h1>Bookstore</h1> <ul> </body> |
The XQuery expression above will generate the following result:
上述XQuery表达式将会输出下面的结果:
<html> <h1>Bookstore</h1> <ul> </body> |