aln447
aln447

Reputation: 1011

XML image path in XSLT

I have a xml file with an index of different video games. Inside of each I would like to have a tag cover with content being a path to the image file like:

<cover>img/swb.jpg</cover>

And later to be able to display it with my xsl file. I'm fairly new to XML, so first thought was to try and do this:

<td><img src='<xsl:value-of select="cover"/>' alt="coverart" /></td>

Easy to figure out, this did not work. 2 hours of google didn't help me either. What is the proper way to deal with this issue?

Will be very grateful for any help.

Upvotes: 1

Views: 1051

Answers (1)

Martin Honnen
Martin Honnen

Reputation: 167401

Use an attribute value template <img src="{cover}" alt="coverart"/> or construct the attribute using xsl:attribute:

<img alt="coverart">
  <xsl:attribute name="src" select="cover"/><!-- XSLT 2.0 and later -->
</img>

<img alt="coverart">
  <xsl:attribute name="src">
    <xsl:value-of select="cover"/><!-- XSLT 1.0 and later -->
  </xsl:attribute>
</img>

Upvotes: 1

Related Questions