以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 XSL/XSLT/XSL-FO/CSS 』  (http://bbs.xml.org.cn/list.asp?boardid=8)
----  在xsl如何进行字符串全局替换  (http://bbs.xml.org.cn/dispbbs.asp?boardid=8&rootid=&id=53501)


--  作者:saniya
--  发布时间:10/8/2007 3:21:00 PM

--  在xsl如何进行字符串全局替换
在xsl中有几个单词多次出现且想在某种情况下用其他字符串全局替换, 怎么实现?
有个template, 不知template要放在什么位置,怎么call 它才行
<xsl:template name="globalReplace">
  <xsl:param name="outputString"/>
  <xsl:param name="target"/>
  <xsl:param name="replacement"/>
  <xsl:choose>
    <xsl:when test="contains($outputString,$target)">
   
      <xsl:value-of select="concat(substring-before($outputString,$target),$replacement)"/>
      <xsl:call-template name="globalReplace">
        <xsl:with-param name="outputString" select="substring-after($outputString,$target)"/>
        <xsl:with-param name="target" select="$target"/>
        <xsl:with-param name="replacement" select="$replacement"/>
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$outputString"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>
--  作者:saniya
--  发布时间:10/8/2007 11:35:00 PM

--  
怎么没人回答啊
<xsl:variable name="yourstring" select="somenode"/>
<xsl:value-of select="translate($yourstring,'aaa','bbb')"/>

--  作者:Qr
--  发布时间:10/9/2007 9:37:00 AM

--  
差不多是这样子了,可以找些关于命名模板的资料来看:
<xsl:template match="/">
       <xsl:call-template name="globalReplace">
              <xsl:with-param name="outputString" select="字符串"/>
              <xsl:with-param name="target" select="字符串"/>
              <xsl:with-param name="replacement" select="字符串"/>
       </xsl:call-template>
</xsl:template>

W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
46.875ms