3

I have an XSLT variable that I'm creating and populating with the value of an attribute at the top of the style sheet like so ...

    <xsl:variable name="MyAttributeValue" select="/Source/Fields/Field[@SpecialAttribute]/@MyAttributeValue" />

Later on in the processing, I want to use $MyAttributeValue as a field name just like I could with a hard-coded string. For example:

<xsl:value-of select="MyField"/>

This will correctly return the value of MyField in the XML while the XSLT is processing. I want to use the variable I defined earlier to do this. For example:

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

So, $MyAttributeValue contains "MyField", but I want the value of MyField in the XML to be displayed rather than the literal text "MyField" when using the variable.

How can that be done?

Thanks!

1 Answer 1

2
<xsl:value-of select="*[local-name() = $MyAttributeValue]" />

will return each child element node with a name equal to the contents of $MyAttributeValue.

If your variable contains a namespace-qualified name, like "foo:MyField", use the name() function instead:

<xsl:value-of select="*[name() = $MyAttributeValue]" />
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.