Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
有没有办法在XPATH 1上正确模拟replace函数?_Xpath - Fatal编程技术网

有没有办法在XPATH 1上正确模拟replace函数?

有没有办法在XPATH 1上正确模拟replace函数?,xpath,Xpath,我有一个函数,它试图用_ 我仅限于使用xpath 1,因此替换函数不是一个选项。该模板的工作效果不太好,因为如果我使用以下内容: FOO-BAR.THING-MADRID.html 它让我在屏幕上看到这件事: FOO-BAR.THING-MADRID.html 中间的圆点不替换 有人能帮我吗 <xsl:template name="replaceDots"> <xsl:param name="outputString"/> <xsl:variable na

我有一个函数,它试图用_

我仅限于使用xpath 1,因此替换函数不是一个选项。该模板的工作效果不太好,因为如果我使用以下内容:

FOO-BAR.THING-MADRID.html

它让我在屏幕上看到这件事:

FOO-BAR.THING-MADRID.html

中间的圆点不替换

有人能帮我吗

 <xsl:template name="replaceDots">
  <xsl:param name="outputString"/>
  <xsl:variable name="target">.</xsl:variable>
  <xsl:variable name="source">-</xsl:variable>
  <xsl:variable name="replacement">_</xsl:variable>
  <xsl:choose>
   <xsl:when test="contains($outputString,$source)">
    <xsl:value-of select="concat(substring-before($outputString,$source),$replacement)" disable-output-escaping="yes"/>
    <xsl:call-template name="replaceDots">
     <xsl:with-param name="outputString" select="substring-after($outputString,$source)"/>
    </xsl:call-template>
   </xsl:when>
   <xsl:when test="contains($outputString,$target)">
    <xsl:value-of select="concat(substring-before($outputString,$target),$replacement)" disable-output-escaping="yes"/>
    <xsl:call-template name="replaceDots">
     <xsl:with-param name="outputString" select="substring-after($outputString,$target)"/>
    </xsl:call-template>
   </xsl:when>
   <xsl:otherwise>
    <xsl:value-of select="$outputString" disable-output-escaping="yes"/>
   </xsl:otherwise>
  </xsl:choose>
 </xsl:template>

.
-
_

要用下划线替换所有点或破折号,您不需要
。您可以使用:

<xsl:value-of select="translate(., '-.', '__')" />

例如,对于XSLT中的通用“字符串替换”模板。

@user:很高兴听到!如果这完全解决了您的问题,请将答案标记为已接受。:-)对不起,我以为我已经接受了答案。我道歉
<xsl:value-of select="
  concat(
    translate(substring-before(., '.html'), '-.', '__'), 
    '.hmtl'
  )
" />