2011-10-20 31 views
1

在XML數據文件中,我有一組圖像<image_list>;在這個集合中,我具有不同名稱的圖像(在<image_result>名稱屬性中給出)。XSL中的引號:使用屬性設置圖像src

我該如何逃避引號才能使用?我試過使用&quot;\"這兩組引號,但emacs亮起紅色,表示格式錯誤。

XSL片斷:

<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> 

回答

7

你的XSLT需要一個良好的XML文檔,所以構造的類型你試圖做到根本不可能。改爲使用Attribute Value Template

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

輝煌,謝謝。爲Google找到正確的東西需要很長時間。 – user

+0

出於某種原因,它只適用於我'' – user

+2

@Oliver - 可能是因爲'name'是源文檔中的一個屬性。 – Oded

2

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

應該這樣做。

2

您可以使用xsl:attribute

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

或精簡選項(使用attribute value template):

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