2014-05-12 51 views
0

我使用的Apache FOP 1.1版建立一個PDF(通過命令行) 這裏是我的XSL是工作的罰款XSL-FO網址功能到模板

<fo:table-row > 
    <fo:table-cell > 
     <fo:block > 
      <fo:external-graphic content-height="9mm" content-width="9mm" height="10mm" width="10mm" scaling="non-uniform" src="url(./images/pict2.jpg)" /> 
     </fo:block> 
    </fo:table-cell> 
</fo:table-row > 

如果我嘗試使用模板以這種方式

<xsl:template name="myRow" > 
    <xsl:param name="imgUrl"/> 
    <fo:table-row > 
     <fo:table-cell > 
      <fo:block > 
       <fo:external-graphic content-height="9mm" content-width="9mm" height="10mm" width="10mm" scaling="non-uniform" src="url($imgUrl)"/> 
      </fo:block> 
     </fo:table-cell> 
    </fo:table-row > 
</xsl:template> 

聲明,我把它作爲

<xsl:call-template name="myRow"> 
    <xsl:with-param name="imgUrl" select="'./images/pict2.jpg'" /> 
</xsl:call-template> 

沒有圖像顯示。 如果我寫入select =「./ images/pict2.jpg」(不帶單引號),則imgUrl參數爲空 如何傳遞url並使其工作?

回答

0

如果你想引用一個屬性中的變量,你需要使用屬性值模板。

試試這個行,而不是在你的模板

<fo:external-graphic content-height="9mm" content-width="9mm" height="10mm" width="10mm" 
        scaling="non-uniform" src="url({$imgUrl})"/> 

大括號指示要計算的表達式,而不是字面直接輸出(這是正在發生的事情在你的代碼的時刻。這是字面上輸出文字$ imgUrl,而不是變量的值)。