EliteKnight
EliteKnight

Reputation: 87

Attribute value when attribute name is a variable

Let's say I have a variable in an XSL sheet like this:

<xsl:variable name="myID" select="."/>

And assume that 'myID' holds an existing attribute name of an XML tag. I want to be able to access the value of that attribute in another file with the same attribute name.

I've tried this:

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

But that doesn't appear to work. What is the proper way to access the value of an attribute with a variable name?

Upvotes: 0

Views: 880

Answers (1)

Tomalak
Tomalak

Reputation: 338376

XPath: "Of all the attributes, pick the one with the name equal to $myID"

<xsl:value-of select="@*[name() = $myID]"/>

Upvotes: 2

Related Questions