- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我有一个 XML 文档,我想将其转换为 HTML。为此,我将 Xquery 与 Oxygen 解析器结合使用。
这是 xml:
<?xml version="1.0" encoding="UTF-8"?>
<?oxygen RNGSchema="file:textbook.rnc" type="compact"?>
<books xmlns="books">
<book ISBN="i0321165810" publishername="OReilly">
<title>XPath</title>
<author>
<name>
<fname>Priscilla</fname>
<lname>Warnley</lname>
</name>
<address>
<street_address>Hill Park<street_address>
<zip>90210</zip>
<state>california</state>
</address>
<phone>00000000</phone>
<e-mail>priscilla@oreilly.com</e-mail>
</author>
<year>2007</year>
<field>Databases</field>
<TOC>
<component>
<type>Part</type>
<title>Xpath</title>
<component>
<title>Chapter... A tour of xquery</title>
<pages>3</pages>
<component>
<title>Introductions</title>
</component>
<component>
<title>Getting started</title>
</component>
</component>
</component>
</TOC>
</book>
<publisher publishername="OReilly">
<web-site>www.oreilly.com</web-site>
<address>
<street_address>hill park</street_address>
<zip>90210</zip>
<state>california</state>
</address>
<phone>400400400</phone>
<e-mail>oreilly@oreilly.com</e-mail>
<contact>
<field>Databases</field>
<name>
<fname>Anna</fname>
<lname>Smith</lname>
</name>
</contact>
</publisher>
</books>
我首先执行此 Xquery 查询:
declare default element namespace "books";
<html>
<head>
<title>Table of contents</title>
</head>
<body>
<b>Table of contents</b>
<hr/>
{ for $i in //book[@ISBN='i0321165810']/TOC
return $i
}
</body>
</html>
基于我的 xml 文档得到这些结果:
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="Books">
<head>
<title>Table of content</title>
</head>
<body>
<b>TOC</b>
<hr/>
<TOC>
<component>
<type>Part</type>
<title>Foundations</title>
<component>
<title>Chapter... A tour of xquery</title>
<pages>3</pages>
<component>
<title>Introductions</title>
</component>
<component>
<title>Getting started</title>
</component>
</component>
</component>
</TOC>
</body>
</html>
我现在想做的是用 pre 标签替换 component 标签(使用空格缩进),用斜体标签替换 title 标签,用粗体标签替换 pages 标签(基本上使用 HTML 标签而不是 XML 标签, 因此可以在 Web 浏览器中查看该文档)。我尝试使用替换功能,但无法正常工作。
有人可以帮忙吗?
最佳答案
正如 DevNull 所指出的,这是 XSLT 大放异彩的任务。这是我的 XQuery 解决方案:
declare default element namespace "http://www.w3.org/1999/xhtml";
declare function local:rename($node) {
let $old-name := local-name($node)
let $new-name :=
switch($old-name)
case 'component' return 'pre'
case 'title' return 'i'
case 'pages' return 'b'
default return $old-name
return element { $new-name } {
$node/@*,
for $nd in $node/child::node()
return if($nd instance of element())
then local:rename($nd)
else $nd
}
};
<html>
<head>
<title>Table of contents</title>
</head>
<body>
<b>Table of contents</b>
<hr/>
{ for $i in //*:book[@ISBN='i0321165810']/*:TOC/*
return local:rename($i)
}
</body>
</html>
函数 local:rename($node)
递归地进入 XML 片段,重建它并替换元素名称。它既不优雅也不高效,但它应该可以完成工作。
我还更改了 默认元素命名空间
,因为您返回的 XHTML 文档位于 books
命名空间中。
关于使用 XQuery 将 XML 文档转换为 HTML 文档 - 需要帮助替换元素标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8300284/
我是 XQuery 初学者。我需要任何软件来运行 XQuery 吗?我在哪里输入 XQuery 代码 - 在 HTML 页面或 XML 中?我应该使用什么扩展名来保存我的 XQuery 文件? 最佳答
我正在编写一个 XQuery,它需要检查正在运行的 XQuery 版本(eXist、Saxon 等)。是否有一个标准函数可以返回 XQuery 的系统属性,例如版本、供应商等? 我知道有一些系统特定的
我正在阅读 book about xQuery它充满了像元素构造函数这样的表达......我的问题是: 什么是元素构造函数,“{}”是元素构造函数吗? 最佳答案 元素构造函数创建一个元素。在 XQue
我在网站上阅读了大量的 XQuery 教程。几乎他们所有人都在教我 XQuery 语法。假设我已经了解了 XQuery 语法,那么我将如何在我的网站上实际实现 XQuery? 例如,我有book.xm
以下有什么区别: import module namespace fs = "http://expath.org/ns/file"; declare namespace an = "http://zo
我有note.xml: Tove Jani Reminder Don't forget me this weekend! 和note.xqy: let $srcDoc:="not
我正在寻找一个示例,它表明 XQuery 表达式评估不是顺序的。在将 XQuery 的功能特性与过程语言进行比较时,总是会提到这一点。 例如在 XQuery, 2nd edition ,在下面的部分:
很难说出这里问的是什么。这个问题是模棱两可的、模糊的、不完整的、过于宽泛的或修辞的,无法以目前的形式得到合理的回答。如需帮助澄清这个问题以便重新打开它,visit the help center .
所以我有一个看起来像这样的 XQuery: for $i in /*:rootElement where $i/*:field = "test" return $i 这个查询返回了很多结果,但我真的只
我有一个xml文档如下 sony vijay 我正在尝试写一个 xquery 1) 找到具有给定用户 ID 的用户 - sony 2) 将给定用户的“test”属性值更改为
是否XQuery更新支持自增属性,就像SQL中的自增字段一样? 我正在使用 BaseX作为我的数据库。 最佳答案 给定 an answer from Christian Grün on the Bas
是否可以使用 XQUERY 来检索属性 filename从以下 XML?我正在尝试使用 /preFileDoc/inpXML/@filename但它不起作用...... ABC XYZ
尝试根据不同的过滤器计算一个集合中的汽车数量。即使我们看到多辆汽车满足要求,查询也返回计数 0。 fn:count(cts:search(fn:collection("com.cars"), cts:
我想在 xquery 中创建一个计数器。我最初的尝试如下所示: let $count := 0 for $prod in $collection let $count := $count + 1 re
我有一系列的值。他们都可以是平等的……或者不是。所以使用 XQuery 我想获得序列中最频繁的项目。 let $counter := 0, $index1 := 0 for $value in $se
当我查找 XQuery 示例时,有时会看到使用了运算符 =>。 我试图寻找它的含义,但找不到任何东西。由于我使用的是 MarkLogic,因此它可能仅适用于 MarkLogic,但我对此表示怀疑。 从
我必须使用 xquery 以 DDMMYYYY 格式创建日期字符串。输入到我的 xquery 的日期将类似于“2004-05-02T00:00:00+01:00”。截至目前,我正在使用以下解决方案来获
我正在使用 XQuery 执行加法。以下是数据库中保存的XML结构: 1 1001 50,1
忙于将 SQLServer 2008 R2 和 MarkLogic 8 与简单的个人实体进行比较。我的数据集适用于 100 万条记录/文档。注意:两个数据库都在同一台机器上(本地主机)。 以下 SQL
想象一下,如果我有一个以下格式存储在 Marklogic 中的 xml 文档: DocumentID question1
我是一名优秀的程序员,十分优秀!