user
user

Reputation: 7333

Quotes in XSL: set image src using attribute

In an XML data file I have a collection of images <image_list>; within this collection, I have images with different names (given in the <image_result> name attribute).

How can I escape the quotes so that this will work? I've tried using &quot; or \" for both sets of quotes, but emacs lights up red, indicating a formatting error.

XSL snippet:

<table>
  <tr>
<xsl:for-each select="image_list/image_result">
  <td>
    <img src ="<xsl:value-of select="name"/>" style="width:450px"/>
  </td>
</xsl:for-each>
  </tr>
</table>

Upvotes: 2

Views: 6087

Answers (3)

Dabbler
Dabbler

Reputation: 9873

<td>
<img src="{name}" style="width:450px"/>
</td>

should do it.

Upvotes: 2

Wayne
Wayne

Reputation: 60424

Your XSLT needs to be a well-formed XML document, so the type of construct you're attempting is simply not possible. Use an Attribute Value Template instead:

<img src="{name}" style="width:450px"/>

Upvotes: 7

Oded
Oded

Reputation: 499232

You can use xsl:attribute:

<td>
  <img style="width:450px">
   <xsl:attribute name="src">
    <xsl:value-of select="name"/>
   </xsl:attribute>
  </img>
</td>

Or the simplified option (using the attribute value template):

<td>
  <img src="{name}" />" style="width:450px"/>
</td>

Upvotes: 3

Related Questions