0

我有一个 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?谢谢。

4

2 回答 2

2

XPathtranslate函数并不像您想象的那样工作。也就是说,它不是一个替换字符串函数。

它将一个列表中的单个字符映射到另一个列表中的相应字符

所以这,

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

意思是,把一个空格翻译成%。第三个参数的20部分被忽略。

于 2013-04-08T16:47:04.953 回答
1

看看这里:XSLT 字符串替换

您可以使用现有的模板,让您使用“替换”功能。

于 2013-04-08T16:52:02.647 回答