Alright, context problem...
Namespace was a wrong guess...

Thanks Gerrit, your solution works and your second beer is marked on my list ;-)
Hope to see you in Prague?

But there's still one last question:

Why do I have to save the value of "@valueOf" in a variable before use in saxon:eval?
Sure, it needs to be treated as a string, but
<xsl:value-of select="$root/saxon:evaluate(string(@valueOf))"/>
<xsl:value-of select="$root/saxon:evaluate(xs:string(@valueOf))"/>
should work as well...
But why don't they?

Am 16.01.2013 22:18, schrieb Imsieke, Gerrit, le-tex:
$namespace-var is only for the namespaces. You want to set the context 
against which the expression is evaluated.

So while input.xml is processed in first place, you may store your 
context in a global variable (because later on, you’re in an HTML div 

   <xsl:variable name="root" select="/" as="document-node(element(root))"/>

and then use

   <xsl:variable name="val" select="@valueOf" as="xs:string"/>
   <xsl:value-of select="$root/saxon:evaluate($val)"/>

further down the road.

You now owe me two beer.


On 2013-01-16 20:35, Tobias Fischer | pagina GmbH wrote:

I'm having a hard time with saxon:expression, saxon:eval, namespaces and
the scope of the evaluated expression.
Maybe someone can be of help on this issue...

It might seem to be a quite complex issue, so let's refer to my test
case as kind of a "template engine".
I put together a small sample...

Let's assume we have an input document ("input.xml") which is beeing
processed by an XSLT 2 stylesheet ("process.xslt") with the help of
Saxon-PE. Output is saved in "output.xml" but shouldn't matter in this

"input.xml" contains information about XHTML documents which need to be
processed in the same transformation because they should "read"
information from "input.xml".
For that reason I sideload these XHTML documents with doc() function and
process the content in a special "mode".

"sideload.xhtml" contains <div> elements with an attribute named
"valueOf" which contains an xpath expression. This expression should be
evaluated on the input document "input.xml".

Is there any way I can evaluate the stored expression in the context of
the input document?
Is it not working because of a namespace issue? Or is it just the wrong
scope in which I want to evaluate the expression?
Or isn't it working at all?...

Thanks for your help.


Master Java SE, Java EE, Eclipse, Spring, Hibernate, JavaScript, jQuery
and much more. Keep your Java skills current with LearnJavaNow -
200+ hours of step-by-step video tutorials by Java experts.
SALE $49.99 this month only -- learn more at:

saxon-help mailing list archived at