我有一个xslt显示没有空格作为字符。
在这种情况下,仅显示%。
URL:
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>
正确的网址应为:
http://localhost:8888/tire/details/Bridgestone/ECOPIA%20EP001S/Bridgestone,ECOPIA%20EP001S,195--65%20R15%2091H,TL,ECO,0
XSLT形成了吗?感谢。
答案 0 :(得分:2)
XPath translate
函数不像您认为的那样工作。也就是说,它不是替换字符串函数。
它将个别字符从一个列表映射到另一个列表中的相应字符。
所以,
translate(@href, ' ', '%20')
表示将空格转换为%
。第三个参数的20
部分被忽略。
答案 1 :(得分:1)
看看这里:XSLT string replace
您可以使用现有的模板,让您使用“替换”功能。