BaseX: where to declare the XML document on which the query is made

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

The document I'm requesting is BookstoreQ.xml .

XPath version working completely fine:

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

      

The XSLT code 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 the BaseX XSLT documentation but couldn't find a solution. How can I run a given XSLT?

+3


source to share


1 answer


BaseX has no direct support for XSLT, you have to call it using XQuery functions (which is easy, though). There are two functions for this, one for returning XML nodes ( xslt:transform(...)

), one for returning text as a string ( xslt:transform-text(...)

). You need a 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 be called using XSLT as nodes (used here) by passing it as a string or by specifying the path to a file containing the XSLT code.

+3


source







All Articles