xslt1.0 替换不起作用 [英] xslt1.0 replace is not working
本文介绍了xslt1.0 替换不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一些带有特殊字符的 URL,我想替换它们,我使用的是 xslt 1.0,所以我正在编写如下代码.
I have URLs with some special characters and i would like to replace them and I am using xslt 1.0 so I am writing the code as below.
<xsl:template name="string-replace-all">
<xsl:param name="text"/>
<xsl:param name="replace"/>
<xsl:param name="by"/>
<xsl:choose>
<xsl:when test="contains($text,$replace)">
<xsl:value-of select="substring-before($text,$replace)"/>
<xsl:value-of select="$by"/>
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text" select="substring-after($text,$replace)"/>
<xsl:with-param name="replace" select="$replace"/>
<xsl:with-param name="by" select="$by"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
并像这样调用:
<td class="ms-vb">
<xsl:variable name="link">
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text" select="@FileRef"/>
<xsl:with-param name="replace" select="'''"/>
<xsl:with-param name="by" select="'%27'"/>
</xsl:call-template>
</xsl:variable>-->
<a target="_blank" href="@link" ><xsl:value-of select="@New_x0020_Doc_x0020_Title" disable-output-escaping="yes" /></a>
</td>
我收到错误无法显示 webpart".谁能建议我在这里做错了什么?
I am getting the error "webpart cannot be displayed". Can anyone please suggest what am i doing wrong here?
推荐答案
提供的替换"模板正在工作.
The provided "replace" template is working.
要确认这一点,请使用以下转换:
To confirm this use the following transformation:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="/*">
<xsl:variable name="link">
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text" select="@FileRef"/>
<xsl:with-param name="replace">'</xsl:with-param>
<xsl:with-param name="by" select="'%27'"/>
</xsl:call-template>
</xsl:variable>
"<xsl:value-of select="$link"/>"
</xsl:template>
<xsl:template name="string-replace-all">
<xsl:param name="text"/>
<xsl:param name="replace"/>
<xsl:param name="by"/>
<xsl:choose>
<xsl:when test="contains($text,$replace)">
<xsl:value-of select="substring-before($text,$replace)"/>
<xsl:value-of select="$by"/>
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text" select="substring-after($text,$replace)"/>
<xsl:with-param name="replace" select="$replace"/>
<xsl:with-param name="by" select="$by"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
在此 XML 文档上应用转换时:
<t FileRef="Abc'Xyz'Tuv"/>
产生想要的、正确的结果:
"Abc%27Xyz%27Tuv"
问题可能出在您指定replace
参数的方式上(表达式中的撇号数量不均匀):
The problem may be in the way you specify the replace
parameter (uneven number of apostrophes in the expression):
代替:
<xsl:with-param name="replace" select="'''"/>
使用:
<xsl:with-param name="replace">'</xsl:with-param>
这篇关于xslt1.0 替换不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文