Crocked
Crocked

Reputation: 1192

Is dynamic evaluation of XPath variable string possible using .NET 2.0 XSLT implementation?

I'm trying to evaluate an XPath varable I'm building dynamically based on the position of the node.

I can create the XPath string in a variable but when I select the value of this just get the string and not the node set I need.

I use the following to create the XPath query.

<xsl:variable name="xpathstring" 
              select="normalize-space(concat(&quot;//anAttribute[@key='pos&quot;,position(),&quot;']&quot;))"/>

And try to output the value with the following.

<xsl:value-of select="$xpathstring"/>

If I execute the XPath query in my debugger I get the nodeset but in my XML output only get the XPath string which looks like this //anAttribute[@key='pos1'].

I had a look at exslt dyn:evaluate which seems to enable this but this seems to be only supported by certain processors and doesn't provide a standalone implementation or at least as far as I could see (currently using the standard .NET 2.0 XSLT which is only XSLT 1.0 as far as I recall.)

Is there any way to handle this without changing processor?

Upvotes: 3

Views: 916

Answers (1)

AxelEckenberger
AxelEckenberger

Reputation: 16936

Why do you not use a param instead of the concatenation:

<xsl:param name="pos">
    <xsl:text>pos</xsl:text>
    <xsl:value-of select="position()"/>
</xsl:param>
<xsl:value-of select="//anAttribute[@key=$pos]"/>

Upvotes: 1

Related Questions