views:

457

answers:

1

Hi ....

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!

A: 
<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]" />
Tomalak
@Tomalak. That did the trick.
OneSource