本文介绍了XSLT 查找和替换回车的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要替换输入 XML 中的回车符.
I need to replace carriage returns from input XML.
输入如下:
<Answer>
<Label>Notes/Comments</Label>
<Value>Q
WERTYU IOPASDFGHJKLZXCVBNM
QWERTYUIOPASDF GHJKLZXCVBNM
QWERTYU IOPASDFGHJKLZXCVBNM
QWERTYUIOPASDFGHJ KLZXCVBNM
QWERTYU IOPASDFGHJKLZXCVBNM
QWERTYUIOPASDFGH JKLZXCVBNM
QWERTYUIOPASDF GHJKLZXCVBNM
QWERTYUIOP ASDFGHJKLZXCVBNM
QWERTYU IOPASDFGHJ KLZXCVBNM
QWERTY UIOPAS DFGHJKLZX CVBNM
QWERTYUIO PASDFGHJ KLZXC VBNM
</Value>
<Iteration>0</Iteration>
<DataType>TEXT</DataType>
</Answer>
我正在尝试使用以下函数删除回车:
I'm attempting to remove carriage returns using the following function:
<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:when test="Label='Notes/Comments'">
<xsl:element name="Comments">
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text" select="Value" />
<xsl:with-param name="replace">
</xsl:with-param>
<xsl:with-param name="by" select="'. '" />
</xsl:call-template>
</xsl:element>
</xsl:when>
但到目前为止还没有成功.我希望只是我传入的字符 (

) 不正确,但我无法使其正常工作.
But so far to no success. I'm hoping it's just that the character (

) I'm passing in is incorrect but I can't get it working.
更新
事实证明,在这种情况下,删除更多的空白字符而不仅仅是回车是可以接受的,因此 normalize-space() 满足我的要求.
As it turns out in this case, removing more white-space characters than just Carriage returns was acceptable and so normalize-space() fulfils my requirements.
推荐答案
您是否检查过除了 
 之外没有

?
Have you checked that you don't have a 
there besides the 

?
这篇关于XSLT 查找和替换回车的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!