2013-04-08 56 views
0

我有一個xslt不顯示空格作爲字符。XSLT中的空白網址

在這種情況下只顯示

網址:

http://localhost:8888/tire/details/Bridgestone/ECOPIA%EP001S/Bridgestone,ECOPIA%EP001S,195--65%R15%91H,TL,ECO,0 

XSL:

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:x="http://www.w3.org/1999/xhtml" version="1.0"> 
    <xsl:param name="extractorHost" /> 
    <xsl:template match="/"> 
    <links> 
     <xsl:apply-templates /> 
    </links> 
    </xsl:template> 
    <xsl:template match="//x:form/x:a[@class='arrow-link forward']"> 
    <xsl:variable name="url" select="translate(@href, ' ', '%20')"/> 
    <link href="{concat($extractorHost, $url)}" /> 
    </xsl:template> 
    <xsl:template match="text()" /> 
</xsl:stylesheet> 

正確的URL應該是:

http://localhost:8888/tire/details/Bridgestone/ECOPIA%20EP001S/Bridgestone,ECOPIA%20EP001S,195--65%20R15%2091H,TL,ECO,0 

難道錯了XSLT形成的?謝謝。

回答

1

到這裏看看:XSLT string replace

您可以使用已有的模板,可以讓你用「替換」功能。

+0

問題出在: 2013-04-08 17:11:54

+0

這解決了我的問題。謝謝。 – 2013-04-08 17:38:31

2

XPath translate函數無法按照您認爲的方式工作。也就是說,它不是替換字符串函數。

它將個別字符從一個列表中的對應的字符列在另一個列表中。

所以這個,

translate(@href, ' ', '%20') 

手段,翻譯的空間分爲%。第三個參數的20部分被忽略。

+0

好的,你說得對。用'substring'做呢? – 2013-04-08 16:54:18