2013-07-10 54 views
3

我寫我的XSL有問題。我有下面的代碼的鏈接:URL編碼與XSLT 1.0

<a> 
<xsl:attribute name="href"> 
    <xsl:value-of select="concat($myUrl,'&amp;projectNumber=',$projectNumber)"/> 
</xsl:attribute> 
<xsl:attribute name="title"> 
    <xsl:value-of select="title"/> 
</xsl:attribute> 
LINK 
</a> 

所以我需要一個變量projectNumber傳遞給的myUrl結束。這工作得很好,我在HTML中獲得...myUrl...&projectNumber=...projectNumber...

問題是,變量projectNumber有時有一些字符必須在我的鏈接的href中轉義。我嘗試使用XSL功能str:escape-uri()在許多不同的方式,但仍然沒有成功...

例如,如果myUrl是www.example.com/example.aspx?a=b和projectNumber是aaaūaaa 我得到href的www.example.com/example.aspx?a=b&projectNumber=aaaūaaa,但我需要得到www.example.com/example.aspx?a=b&projectNumber=aaa%C5%ABaaa。 (%C5%AB是'ū'逃跑的方式)有什麼建議嗎?謝謝。

回答

7

如果您使用的是XSLT 1.0, ,則請參閱this

對於XSLT 2.0,您可以使用它來解決問題。

<xsl:value-of select="concat($myUrl,'&amp;projectNumber=',encode-for-uri($projectNumber))"/> 
+0

試圖用的,而不是「編碼換URI」編碼-URI「相同的代碼,但它仍然無法正常工作兩種方式:/ –

+0

使用嵌入的JScript試過嗎? –

+0

不,我沒有試過,你能告訴我一個例子,我怎樣才能將projectNumber傳遞給嵌入式JScript並返回轉義的projectNumber? –