tags:

views:

183

answers:

1

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?

+1  A: 

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]"/>
Obalix
Thanks that works fine. I was banging my head against a wall trying to get it to work from the xpath string directly but this works fine.
Crocked
Glad to have helped.
Obalix