Link to home
Start Free TrialLog in
Avatar of Dmitry_Bond
Dmitry_BondFlag 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.
Avatar of sweetfa2
sweetfa2
Flag of Australia image

As far as I know this is not supported.
ASKER CERTIFIED SOLUTION
Avatar of Dmitry_Bond
Dmitry_Bond
Flag of Ukraine image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 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".