BaseX:在哪里声明要对其执行查询的 XML 文档 [英] BaseX: where to declare the XML document on which to perform a query

查看:41
本文介绍了BaseX:在哪里声明要对其执行查询的 XML 文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过 BaseX 程序,我能够使用 XPath 和 XQuery 来查询位于我的主目录中的 XML 文档,但我在 XSLT 中执行相同操作时遇到问题.

With the program BaseX I was able to use XPath and XQuery in order to query an XML document located at my home directory, but I have a problem with doing the same in XSLT.

我正在查询的文档是 BookstoreQ.xml.

The document I'm querying is BookstoreQ.xml.

XPath 版本,运行完全正常:

XPath version, running totally fine:

doc("/home/ioannis/Desktop/BookstoreQ.xml")/Bookstore/Book/Title

我要执行的 XSLT 代码:

XSLT code which I want to execute:

<xsl:stylesheet version = "2.0" xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">
  <xsl:output method= "xml" indent = "yes" omit-xml-declaration = "yes" />
  <xsl:template match = "Book"></xsl:template>
</xsl:stylesheet>

我阅读了 BaseX 关于 XSLT 的文档,但没有找到解决方案.如何运行给定的 XSLT?

I read BaseX' documentation on XSLT, but didn't manage to find a solution. How can I run given XSLT?

推荐答案

BaseX 不直接支持 XSLT,您必须使用 XQuery 函数调用它(虽然这很容易).有两个函数可以执行此操作,一个用于返回 XML 节点(xslt:transform(...)),用于将文本作为字符串返回 (xslt:transform-text(...)).你需要第二个.

BaseX has no direct support for XSLT, you have to call it using XQuery functions (which is easy, though). There are two functions for doing this, one for returning XML nodes (xslt:transform(...)), one for returning text as a string (xslt:transform-text(...)). You need the second one.

xslt:transform-text(doc("/home/ioannis/Desktop/BookstoreQ.xml"),
  <xsl:stylesheet version = "2.0" xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">
    <xsl:output method= "xml" indent = "yes" omit-xml-declaration = "yes" />
    <xsl:template match = "Book"></xsl:template>
  </xsl:stylesheet>
)

两者都可以使用 XSLT 作为节点(此处使用)调用,方法是将其作为字符串传递或提供包含 XSLT 代码的文件的路径.

Both can either be called with the XSLT as nodes (used here), by passing it as a string or giving a path to a file containing the XSLT code.

这篇关于BaseX:在哪里声明要对其执行查询的 XML 文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆