Matching elements with a name specified by an attribute value

Subject: Matching elements with a name specified by an attribute value
From: "SCOTT, Darren, FM" <Darren.Scott@xxxxxxxx>
Date: Fri, 20 Oct 2000 13:58:21 +0100
Is it possible to match on elements where the names of the elements to look
for are specified as the attribute values of other elements ie. the element
name to match is specified at processing time?

Consider the example source XML...

<layout>
  <layout_item data_element="item1"/>
  <layout_item data_element="item2"/>
  <layout_item data_element="item3"/>
</layout>

<item1>I am item 1</item1>
<item2>I am item 2</item2>
<item3>I am item 3</item3>

In this example, I am intending that the <layout> element and it's child
<layout_item> elements specify the order and placement of items, and the
data for these items is specified in the elements referenced by the
"data_element" attributes.

So when the XSLT processes the first <layout_item> element it would need to
fetch the data value from the element specified in its "data_element"
attribute, namely <item1>. This is repeated until all <layout_item>s have
been processed.

I can get this method to work when matching on attribute values instead of
element names ie. each <item1>, <item2> etc element has another attribute
(say "data_ref") which specifies the value that the "data_element"
references. In this case a simple XPath predicate such as
[@data_element=@data_ref] does the job.

Can anyone suggest a way of achieving this, if it is at all possible?


********************************************************************
This e-mail is intended only for the addressee named above.
As this e-mail may contain confidential or privileged information,
if you are not the named addressee, you are not authorised to
retain, read, copy or disseminate this message or any part of it.
********************************************************************


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread