tags:

views:

17

answers:

1

Hi

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 ?

+3  A: 

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.

musiKk
thx xsl:attribute does the job. and thx for the info about "{$some-variable-here}", I should check to know the way it works.
Stephane Rolland
It should. I revised my answer.
musiKk
@musikk and @Stephane Rolland: Whenever you can use literal result elements and AVT, use it. It's fast and compact.
Alejandro