I have this function which tries to replace dots and/or - with _
I'm limited to use xpath 1 so replace function is NOT an option. The template works not to much fine because if I use something like this:
FOO-BAR.THING-MADRID.html
it gives me out on screen this thing:
FOO-BAR.THING-MADRID.html
the middle dot is not replaced.
Someone could help me?
 <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>
To replace all dots or dashes with underscores, you do not need an <xsl:template>. You can use:
<xsl:value-of select="translate(., '-.', '__')" />
If you want to keep the ".html", you can extend this like so:
<xsl:value-of select="
  concat(
    translate(substring-before(., '.html'), '-.', '__'), 
    '.hmtl'
  )
" />
For a generic "string replace" template in XSLT, look at this question, for example.
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论