I'm trying to run many xpath queryes written in a configuration xml file on an input xml file:
<results>
<xsl:for-each select="$config_file/queries/*">
<xsl:variable name="curr_item_name" select="name()"></xsl:variable>
<xsl:variable name="curr_xpath_query" select="."></xsl:variable>
<xsl:element name="{$curr_item_name}">
<xsl:value-of select="dyn:evaluate($curr_xpath_query)" />
</xsl:element>
</xsl:for-each>
</results>
I was expecting to have many xml element children of results (as many as queries' children) with the xpath evaluation result.
I get all tags named correctly but empty.
Cana anyone help me? As processor I'm using Xalan eclipse embedded processor (for now).
Thanks, Laura
So which node do you want to be the context node for your XPath evaluation? Currently it is any element you process with $config_file/queries/*
and you use to provide the XPath expression. You probably want to store the XPath expression in a variable and then change the context with for-each
or apply-templates
to some other node you have not shown and which is not accessible if you haven't stored it previously in a variable. So let's assume you have a global variable
<xsl:variable name="main-doc" select="/"/>
and then you can use e.g.
<xsl:variable name="path-exp" select="."/>
<xsl:for-each select="$main-doc//foo">
<xsl:value-of select="dyn:evaluate($path-exp)" />
</xsl:for-each>