Whitespace trimming demo

/xml/stylesheets/trim/

File Name  ↓ File Size  ↓ Date  ↓ 
--
30122015-Oct-24 21:04
29382004-Mar-04 01:34

Description: XPath's normalize-space() strips leading and trailing whitespace, and also collapses runs of whitespace in the remaining text to a single space character. If you want to only strip the leading and/or trailing whitespace, there is no built-in function to do it. However, it is possible to use other XPath 1.0 functions in combination to strip leading whitespace, and it is possible to use a recursive template in XSLT to strip trailing whitespace. This stylesheet demonstrates both operations.

Requirements: Any XSLT 1.0 processor should be able to handle this, but not all processors optimize tail recursion. Therefore, when processing strings with thousands of trailing whitespace characters, one may run into stack limits.

See also: similar functions implemented in FXSL.