Alex Rivera | Logout

Xslt generating Html <IMG> tags. How to use an XML node value as an src-attribute for the <IMG> Tags

Asked 2010-09-02T09:34:29.043
11

I'm still searching, but I haven't found yet the way to perform something like this:

xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <!-- some other templates -->
    <xsl:template match="IMAGE">
        <img src="src_attribute_to_be_read_from_the_xml_file.jpg"/>
    </xsl:template>     
</xsl:stylesheet>

In my Xml <IMAGE> tags, the text value is the filename that should be inserted in the string src_attribute_to_be_read_from_the_xml_file.jpg when processed by this Xslt file.

Have you any idea to perform this ?

Edit
Report

1 Answer

36

You use xsl:attribute:

<img>
    <xsl:attribute name="src">
        <xsl:value-of select="you path here"/>
    </xsl:attribute>
</img>

It should also be possible to use

<img src="{some expression here}" />

According to the specification this is called a attribute value template and should always work (i.e. both XSLT 1.0 and 2.0). Nice. Now I learned something too.

answered 2010-09-02T09:38:56.130

Your Answer