Avatar of Dmitry_Bond
Dmitry_Bond
Flag for Ukraine asked on

XML/XSLT translation - how to read attribute with calculated name?

Hi.

I need to get in XSLT an attribute with dynamically calculated name.
So, need to do something like this:
<xsl:variable name="attrName" select="concat('@', name())" />
<xsl:choose>
  <xsl:when test="//ColumnsRenamer/$attrName != ''">
    <xsl:value-of select="//ColumnsRenamer/$attrName" />
  </xsl:when>
  <xsl:otherwise>
    <xsl:value-of select="name()" />
  </xsl:otherwise>
</xsl:choose>

Open in new window


In other words - in the XML like this:
<Document>
  <ColumnsRenamer Field1="Some other name"/>
  <Record>
    <Field1>111</Field1>
    <Field2>222</Field2>
  </Record>
</Document>

Open in new window


When processing the <Field1> XML element I need to read a "Field1" attribute from another XML element.

Is it possible to do with standard XSTL features? I mean - it should works in any web browser (almost in any, enough if it will work in IE, FireFox, Opera).

This XSLT code sample seems does not work. It is reporting "XSLT Compile error at <xsl:when test="//ColumnsRenamer/$attrName != ''">".

Regards,
Dmitry.
Web Languages and StandardsWeb Development

Avatar of undefined
Last Comment
Dmitry_Bond

8/22/2022 - Mon
sweetfa2

As far as I know this is not supported.
ASKER CERTIFIED SOLUTION
Dmitry_Bond

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Dmitry_Bond

ASKER
The answer like "is not possible" or "is not supported" is not the answer supposed to be.
So, I found solution by myself and posted as a kind of "workaround".
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy