The saxon:evaluate() extension function takes as input a string containing an XPath expression, and returns the result of evaluating that expression, which seems to be exactly the function that you want. Read the spec carefully to make sure you understand the rules for the context of the expression.
I'm not convinced this is the right design in your case. A cleaner (faster and more standard) solution might be a recursive function:
<xsl:function name="f:select-args" as="element(argument)*">
  <xsl:param name="plist" as="element(parm_list)*"/>
  <xsl:param name="path" as="xs:string+"/>
  <xsl:variable name="step" select="$plist/argument[name=$path[1]]"/>
     <xsl:when test="exists($path[2])">
        <xsl:sequence select="f:select-args($step/parm_list, remove($path[1]))"/>
        <xsl:sequence select="$step"/>
<xsl:for-each select="f:select-args(/command/parm_list, remove(tokenize(path, '\s+'), 1))">
Michael Kay

From: [] On Behalf Of Tom Voltz
Sent: 05 December 2005 23:12
Subject: [saxon] xslt 2.0: variable as an xpath expression?

I have been banging my head against the wall on this one problem, and thought saxon experts might have some ideas.  (I’m using XSLT 2.0 for this project..)


I have built up a variable that will help me locate a specific node in my document as follows:


<xsl:variable name="argument_xpath">/command<xsl:for-each select="remove(tokenize(path,'\s+'),1)">/parm_list/argument[name='<xsl:value-of select="."/>']</xsl:for-each>


Given the value of path is “clock set time”,

The result of the code above is:



However, I can not for the life of me figure out how to get this to be parsed by Saxon as an xpath expression instead of a string value:

<xsl:for-each select=”’$argument_xpath’”> . . .

Does not work, nor does the variation:

<xsl:for-each select=”’/command/$argument_xpath’”> . . (Assuming I truncated the variable so this is a correct xpath that will find the target node.)


I can of course use variables within an xpath expression, in some contexts:

//command[name=’$x’] for example works like a charm.


Any hints or ideas on how to get Saxon to treat an entire $variable as an xpath expression to be evaluated against the main document?