xml XSL 从文本中删除换行符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1922882/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
XSL Remove a line break from text
提问by joe
I would like to remove the line break that follows all text that says See the Exhibit "
我想删除所有显示“查看展览”的文本后面的换行符
Unwanted linebreak as shown in notepadd++:
不需要的换行符,如 notepadd++ 所示:
alt text http://img13.imageshack.us/img13/9803/clcflinebreak.png
替代文字 http://img13.imageshack.us/img13/9803/clcflinebreak.png
This is what I have so far:
这是我到目前为止:
<xsl:template match="p">
<!-- output everything but the See the exhibit text should have the line break removed -->
</xsl:template>
Any ideas? Thanks!
有任何想法吗?谢谢!
采纳答案by joe
<!-- Get text. Replace all “break with “ -->
<xsl:variable name="linebreak">
<xsl:text>
</xsl:text>
</xsl:variable>
<xsl:variable name="text">
<xsl:call-template name="replace-string">
<xsl:with-param name="text" select="."/>
<xsl:with-param name="replace" select="concat('“',$linebreak)" />
<xsl:with-param name="with" select="string('“')"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="$text"/>
回答by Robert Rossney
If you're using your transform to generate HTML output, the simplest approach is usually:
如果您使用转换生成 HTML 输出,最简单的方法通常是:
<xsl:value-of select="normalize-space($text)"/>
normalize-spacestrips leading and trailing whitespace, and replaces runs of multiple whitespace characters within the string with a single space.
normalize-space去除前导和尾随空格,并用单个空格替换字符串中的多个空格字符。
To remove exactly a trailing CR/LF pair:
要准确删除尾随 CR/LF 对:
<xsl:choose>
<xsl:when test="substring(., string-length(.)-1, 2) = '
'">
<xsl:value-of select="substring(., 1, string-length(.)-2)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>

