2012-05-01 33 views
60
<a> 
    <xsl:attribute name="href"> 
    <xsl:value-of select="/*/properties/property[@name='report']/@value" /> 
    </xsl:attribute> 
</a>  

有什麼辦法來cancat另一個字符串如何Concat的一個字符串,XSL:value-of的選擇=」 ...

<xsl:value-of select="/*/properties/property[@name='report']/@value" /> 

我需要通過一些文字href屬性的除了報告屬性值

回答

103

您可以使用名爲CONCAT這裏

<a> 
    <xsl:attribute name="href"> 
     <xsl:value-of select="concat('myText:', /*/properties/property[@name='report']/@value)" /> 
    </xsl:attribute> 
</a> 
相當理智命名XPath函數

當然,它不一定是文本,它可以是另一個xpath表達式來選擇元素或屬性。你可以在concat表達式中有任意數量的參數。

待辦事項,您可以使用屬性值模板(用花括號表示)這裏來簡化你的表達

<a href="{concat('myText:', /*/properties/property[@name='report']/@value)}"></a> 
+2

@TimC:好,但'CONCAT()'函數是沒有必要在這裏。 –

+0

我有以下標記:'Anders, John',我想在XSLT中創建一個只帶ID#的隱藏字段。我怎樣才能做到這一點? – SearchForKnowledge

14

使用

<a href="wantedText{/*/properties/property[@name='report']/@value)}"></a> 
17

三個答案:

簡單:

<img> 
    <xsl:attribute name="src"> 
     <xsl:value-of select="//your/xquery/path"/> 
     <xsl:value-of select="'vmLogo.gif'"/> 
    </xsl:attribute> 
</img> 

使用的concat:

<img> 
    <xsl:attribute name="src"> 
     <xsl:value-of select="concat(//your/xquery/path,'vmLogo.gif')"/>      
    </xsl:attribute> 
</img> 

屬性快捷通過@TimC

<img src="{concat(//your/xquery/path,'vmLogo.gif')}" /> 
+1

正如Dimitre所說,你不需要這裏的concat:'' – Svish

3

作爲建議Concat的一個靜態文本字符串到所選擇的值是使用元件的最簡單方法。

<a> 
    <xsl:attribute name="href"> 
    <xsl:value-of select="/*/properties/property[@name='report']/@value" /> 
    <xsl:text>staticIconExample.png</xsl:text> 
    </xsl:attribute> 
</a> 
-1

最簡單的方法是

<TD> 
    <xsl:value-of select="concat(//author/first-name,' ',//author/last-name)"/> 
    </TD> 

當XML結構

<title>The Confidence Man</title> 
<author> 
    <first-name>Herman</first-name> 
    <last-name>Melville</last-name> 
</author> 
<price>11.99</price>