5

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?

Stefan van den Akker
  • 6,661
  • 7
  • 48
  • 63
  • Did you have a look at [XSLT documentation for BaseX' ](http://docs.basex.org/wiki/XSLT_Module)? Please provide more information on what you're trying to do and how you're code looks like, your question is much to vague to answer it. – Jens Erat Feb 18 '13 at 23:07
  • @Jens Erat Yes, I read the XSLT documentation for BaseX but I didn't manage to find a solution. The document that I want to query over is on the Desktop With XPath in BaseX's Editor I write `doc("/home/ioannis/Desktop/BookstoreQ.xml")/Bookstore/Book/Title` My question is in XSLT where I have to write the path to the document ("BookstoreQ.xml") that I want to query over ` ` – Ioannis Papaioannou Feb 19 '13 at 19:38
  • I edited your new information to your question. Next time posting a question, give all relevant information (including expected input/output) in your question, you will get an answer much faster. Kind regards, Jens – Jens Erat Feb 19 '13 at 20:07

1 Answers1

3

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.

Jens Erat
  • 37,523
  • 16
  • 80
  • 96
  • Error: Stopped at line 6, column 1 in /home/ioannis/Desktop/file: [XPST0017] Unknown function 'xslt:transform-text(...)'. Query: xslt:transform-text(doc("/home/ioannis/Desktop/BookstoreQ.xml"), ) – Ioannis Papaioannou Feb 20 '13 at 17:13
  • Are you using the most current version of BaseX? Just realized, that function just was released with BaseX 7.6 this year. – Jens Erat Feb 20 '13 at 17:46
  • at ubuntu's software center there is the 7.3 version so I switch to the windows to use 7.6 now works but the output is a bit strange: <BookTitle>A First Course in Database Systems</BookTitle&gt instead of A First Course in Database System – Ioannis Papaioannou Feb 22 '13 at 05:50
  • When you want XML as a result, don't use `xslt:transform-text(...)` but `xslt:transform(...)`. – Jens Erat Feb 22 '13 at 09:05