Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

xslt

xquery

basex

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?

like image 251
Ioannis Papaioannou Avatar asked Oct 22 '22 17:10

Ioannis Papaioannou


1 Answers

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.

like image 178
Jens Erat Avatar answered Nov 11 '22 17:11

Jens Erat