1

I work in xslt 2.0 and I have a line in my code like this:

<xsl:value-of select="//dbquery[@id='INLIJVING']//rows/row[@BudgetaryEnvelop_Year = $RefBef][1]/@BudgetaryEnvelop_Year"/></xsl:variable>

This works fine. But I want to write this with a dynamic parameter name instead of @BudgetaryEnvelop_Year.

I tried to define a param $target and to change the line like this:

<xsl:value-of select="//dbquery[@id='INLIJVING']//rows/row[$target = $RefBef][1]/@BudgetaryEnvelop_Year"/></xsl:variable>

But this doesn't work. It doesn't execute the value-of. I tried to pass it like a string like this:

<xsl:value-of>
    <xsl:attribute name="select">//dbquery[@id='INLIJVING']//rows/row[<xsl:value-of select="$target"/>=<xsl:value-of select="$RefBef"/>][1]/@BudgetaryEnvelop_Year</xsl:attribute>
</xsl:value-of>

But that doesn't work either.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Bigjo
  • 613
  • 2
  • 10
  • 32

2 Answers2

0

If you want to compare an attribute specified by a variable, try something like:

row[ @*[ name() = $attrName ] = $RefBef ]

@* matches any attribute and the nested predicate filters the one with name $attrName. (So $attrName should not contain the @ character.)

If you want to evaluate whole expressions dynamically, you'll need extension functions. See the question Evaluate dynamic string as an XPath expression.

Community
  • 1
  • 1
nwellnhof
  • 32,319
  • 7
  • 89
  • 113
0

Try an XPath similar to;

<xsl:value-of select="//dbquery[@id='INLIJVING']//rows/row/@*[local-name()=$target]/../@BudgetaryEnvelop_Year"/>

The @* returns all the attributes of row which we then filter by the name of the attribute. This leaves the XPath as selecting the attribute which is not what's desired so we use .. to ascend back to row and decend into the desired @BudgetaryEnvelop_Year attribute.

Adam
  • 4,180
  • 2
  • 27
  • 31