質問

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?

役に立ちましたか?

解決

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top