BaseX: where to declare the XML document on which to perform a query

倖福魔咒の 提交于 2019-12-10 15:54:27

问题


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.

The document I'm querying is BookstoreQ.xml.

XPath version, running totally fine:

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

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>

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


回答1:


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>
)

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.



来源:https://stackoverflow.com/questions/14946060/basex-where-to-declare-the-xml-document-on-which-to-perform-a-query

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!