KyleM
KyleM

Reputation: 121

XSL for-each filtering; how to evaluate TWO variable in select?

<xsl:variable name="filterValue"
 >@subject = 'Subject To Filter On'</xsl:variable>
<xsl:for-each select="$Rows[$filterValue]">

It seems to me that the $filterValue is being treated as a literal string rather than being evaluated. How can I make it so that the variable's value is evaluated instead?

Desired result:

<xsl:for-each select="$Rows[@subject = 'Subject To Filter On']">

I apologize if this has been answered before, I don't know much terminology about XSL so I'm having trouble searching online. Thanks.

Upvotes: 1

Views: 1194

Answers (1)

Dimitre Novatchev
Dimitre Novatchev

Reputation: 243529

Dynamic evaluation of XPath expressions is not supported in both XSLT 1.0 and XSLT 2.0.

Usually, there are workarounds.

In this specific case you can have (global/external) parameters:

  <xsl:param name="attrName" select="'subject'"/>
  <xsl:param name="attrValue" select="'Subject To Filter On'"/>

and then in your code:

<xsl:for-each select="$Rows[@*[name()=$attrName] = $attrValue]"> 

Upvotes: 1

Related Questions