2013-04-08 59 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