开发者

Remove line feed (LF) from XML node using XSLT

I have the following in an XML node:

<TR_Comment>XXX YYY ZZZ
</TR_Comment>

(as you can see there is a line feed)

My XSLT is really simple:

<开发者_StackOverflow社区;xsl:value-of select="a:Common/a:TR_Comment"/>

How can I remove the line feed using XSLT?


Does normalize-space(a:Common/a:TR_Comment) do what you want?

If you are really keen on preserving inner whitespace, it can get a bit inelegant. One way is to make a recursive template that uses string-length and substring to keep removing characters from the end, one at a time, until there is no trailing whitespace.


Use:

translate(., '&#10;&#13;', '')

when this expression is evaluated, the result is the string value of the current node from which any NL or CR characters are removed.

Do note that no other characters are deleted or modified, so this is a more precise solution and may be preferrable in some cases over normalize-space()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜