結果才發現xsl沒有replace的function,原本以為用translate就可以搞定
結果用法整個不太一樣…冏rz
後來google到別人寫好的replace function,就來趕快記錄一下
<xsl:template name="replace-string">
<xsl:param name="text"/>
<xsl:param name="replace"/>
<xsl:param name="with"/>
<xsl:choose>
<xsl:when test="contains($text,$replace)">
<xsl:value-of select="substring-before($text,$replace)"/>
<xsl:value-of select="$with"/>
<xsl:call-template name="replace-string">
<xsl:with-param name="text" select="substring-after($text,$replace)"/>
<xsl:with-param name="replace" select="$replace"/>
<xsl:with-param name="with" select="$with"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
call template example:<xsl:call-template name="replace-string"> <xsl:with-param name="text" select="'aa::bb::cc'"/> <xsl:with-param name="replace" select="'::'" /> <xsl:with-param name="with" select="','"/> </xsl:call-template>