johkar
johkar

Reputation: 435

Dynamic path in document function()

The XML file name is specific but I need to build a dynamic path. I have tried using a variable to build the path but it didn't work:

<xsl:variable name="path">
   ...conditional code
</xsl:variable>     <xsl:value-of select="document('myXML.xml')/worksheets/$path"/> 

2.0 solutions ok.

Upvotes: 2

Views: 3080

Answers (2)

Dimitre Novatchev
Dimitre Novatchev

Reputation: 243479

Evaluation of any dynamically-generated XPath expression is not supported by the XSLT 1.0 or XSLT 2.0 standards. It will be supported in XSLT 2.1.

If the dynamically-generated XPath expression is not too complex, the technique in this answer can be used successfully:

Retrieving XML node from a path specified in an attribute value of another node

Upvotes: 1

Max Toro
Max Toro

Reputation: 28608

You need an extension function, XPath 2.0 does not support dynamic compilation/evaluation. Saxon has saxon:evaluate. Even if your processor does not support such function you might be able to implement it yourself as an extension function.

Upvotes: 1

Related Questions