Using XSLT variable in X PATH string

1.2k Views Asked by At

I have an XPath string as follows:

/results/server[@name='server1']

I would like to construct a new XPath using a previously defined XSLT variable:

/results/server[@name='$server']

I haven't tried 'concat' might be possible with that. I am using XSLT 2.0. XSLT parser complains if I use the string as defined above:

XPST0003 XPath syntax error at char 65 on line 89 near: Unexpected token "" in path expression

1

There are 1 best solutions below

4
Florent Georges On BEST ANSWER

You can refer to the variable anywhere in the XPath expression:

/results/server[@name eq $server]

If you write it with quotes, '$server', then it is just a string literal that happens to contain a dollar sign.