[xsl] Selecting an element by a dynamic attribute value

Subject: [xsl] Selecting an element by a dynamic attribute value
From: "Rupert Parson" <rupert.parson@xxxxxxxxxxxxxxxxx>
Date: Tue, 24 Jan 2006 12:06:29 -0000
Dear all,

I have an XML file which looks something like this:

--------------------------------------------------------------

<results>
	<graphs>
		<graph label="foo" file="graph0.gif"/>
		<graph label="bar" file="graph1.gif"/>
		<graph .... etc />
	</graphs>

	<data>
		<run label="foo">
			<some data elements>
			</some data elements>
		</run>
		<run label="bar">
			<some data elements>
			</some data elements>
		</run>
	</data>
</results>

---------------------------------------------------------------

For irritating reasons, the graphs part and the data part are produced by
two different pieces of code, so can't be combined (the file attribute of
<graph> elements can't be inserted into the <run> elements in the xml file).

I would like to render this using xsl. I have up to now just been rendering
the <data> element in the xml file, using an <xsl:for-each> to loop around
the <run> elements.

I would like to insert into each of the <run> element renderings an html
<img> element. This <img> element would have an href attribute being the
value of the file attribute of the <graph> element with matching label (i.e.
the same label attribute value as the <run> element I am currently
rendering). Is there any way to do this?

Many thanks in advance for your help,

Rupert Parson

Current Thread