Ask the Expert

Insert an XSL variable into an XPath expression

I want to be able to declare an XSL variable, and then insert its value into an XPath expression like this:

However, this never works and I suspect the variable is being converted to a string, and what is expected by XPath is a nodeset. I have tried converting to a node-set first to get around this, but it doesn't work. I know I could use another language to do this, but I need to do it with XSLT for project-specific reasons. Is there any way to assign a value to a variable, and then embed that variable within an XPath or other expression?

    Requires Free Membership to View

This e-mail may answer your question:

Note the difference between:
<xsl:variable name="target" select="elementname"/>
<xsl:variable name="target" select="'elementname'"/>

This was first published in April 2004

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: