Is it possible to dynamically evaluate an XPath string variable using the .NET 2.0 XSLT implementation?

I am trying to evaluate XPath varable. I am building dynamically based on node position.

I can create an XPath string in a variable, but when I select a value, we just get the string, not the node set that I need.

I use the following to create an XPath query.

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

And try to print the value with the following.

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

If I execute an XPath query in my debugger, I get a set of nodes, but in my XML output, I get only an XPath string that looks like //anAttribute[@key='pos1'].

I looked at exslt dyn:evaluatewhich seems to have enabled this, but it seems to be supported only by some processors and does not provide a standalone implementation, or at least as far as I could see (currently using the standard .NET 2.0 XSLT , which as far as I remember, is only XSLT 1.0.)

Is there any way to handle this without changing the processor?

+3
source share
1 answer

Why don't you use parameter instead of concatenation:

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

Source: https://habr.com/ru/post/1736780/


All Articles