如何使用fn:替换为XSL

时间:2013-10-03 22:48:51

标签: xml xslt

我正在尝试使用会员链接替换xml输出中的XXXXX。我认为替换功能是一个选项,但我无法使其正常工作。

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  <html>
  <body>
  <h2>PayDotCom (By Popularity)</h2>
  <table border="1">
    <tr bgcolor="#9acd32">
      <th>Score</th>
      <th>Affiliate Link</th>
      <th>Name</th>
    </tr>
    <xsl:for-each select="marketplace/Product">
    <tr>
      <td><xsl:value-of select="aps"/></td>
      <td><xsl:value-of select="salespage"/></td>
      <td><xsl:value-of select="name"/></td>
    </tr>
    </xsl:for-each>
  </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>

以下是XML输出的片段,其中显示了Affiliate Link下的XXXXX。

PayDotCom (By Popularity)

Score     Affiliate Link                            Name
52949.7   http://paydotcom.com/r/95330/XXXXX/       The Best Spinner
27828.8   http://paydotcom.com/r/10031/XXXXX/       My Data Team Global Data Entry &     Traditional Data Entry Jobs
12750.9   http://paydotcom.com/r/16329/XXXXX/       3WayLinks.net Subscription
10380.4   http://paydotcom.com/r/9912/XXXXX/        Instant Article Wizard
9438.49   http://paydotcom.com/r/98870/XXXXX/       The Smart Cash System - Make $4000 Per Week From Home

如果我需要澄清更多,请告诉我。提前谢谢。

1 个答案:

答案 0 :(得分:1)

replace()是一个XPath 2.0函数,仅在XSLT 2.0(和3.0)中可用。

您的样式表是XSLT 1.0。

substring-before()是XSLT 1.0中提供的XPath 1.0函数:

<xsl:value-of select="substring-before(salespage, 'XXXXX')"/>