I’ve got the following …
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
(etc.) >
<xsl:param name="Query"/>
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<r:results>
<xsl:for-each select="$Query">
(etc.)
</xsl:for-each>
</r:results>
</xsl:template>
</xsl:stylesheet>
I want the value of the Query parameter to be the select of the for-each.
When I execute this transformation in C# I get … Expression must evaluate to a node-set.
I know it’s coming from the select because if I replace $Query with a hard-coded expression (the same value that I’m passing as the parameter value) it works fine.
Any ideas? Is this even possible?
Frank
XSLT is compiled, and does not (according to the standard) support XPath re-evaluation at runtime – only at compile-time.
Some processors, such as Saxon, do have extensions to allow this, although they run with some limitations. You might want to check out the .Net version of the Saxon XSLT processor (.Net API page). Saxon has an extension function called saxon:evaluate which lets you do runtime XPath construction and evaluation.
The built-in Microsoft XSLT engine does not support calculated
selectXPath expressions.One work-around is to build the XSLT as a string, substitute in your path, and then run it that way.