1

Currently, I'm writing something to do Unit testing for XSLT2 functions, the idea is very simple:

  1. Create a custom-library.xsl, which contains some custom XSLT2 functions.
  2. Create a data XML contains the test cases, as following XML Schema xslunit.xsd:

    schema structure http://xml.bodz.net/schema/xslunit/xslunit.png

  3. Run the test cases by transform it, using xslunit-xslt2.xsl, and get the test result html.

Now, the question is, there is function-call in the test cases, and I have to evaluate it in the XSLT (file xslunit-xslt2.xsl). But I can't find a way to evaluate an XPath.

Though, it may be easy to using some kind of Java extensions, but I really don't want to bring in another trouble. I hope everything can just work with-in XSLT2 only.

Lenik
  • 13,946
  • 17
  • 75
  • 103

2 Answers2

1

No, pure XSLT 2.0 does not have support do evaluate an XPath expression found in your XML data. Saxon 9 (in its commercial editions) however has an extension function: http://www.saxonica.com/documentation/extensions/functions/evaluate.xml. And AltovaXML Tools has a similar one: http://manual.altova.com/AltovaXML/altovaxmlcommunity/index.html?xextaltova_general.htm

Martin Honnen
  • 160,499
  • 6
  • 90
  • 110
  • I guess http://exslt.org/dyn/functions/evaluate/index.html is also worth mentioning. It's implemented, for example, in libxslt, which is still in 1.0 world. – Flack Jan 04 '11 at 13:27
  • thanks for the altova link, though I'm just use the editor at all. If I have determined which tool to use, there is always an extension way. So I'm considering a different approach for unit testing of xslt. – Lenik Jan 04 '11 at 15:06
1

Update a decade later: XSLT 3.0 has an instruction <xsl:evaluate> which evaluates an XPath expression supplied dynamically as a string.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164