Well, in an ideal world you could use an XSLT 2.0 processor, or failing that, an XSLT 1.0 processor that implements tail recursion. But if you can't do either of those things then (assuming you only want to solve the specific problem of removing trailing spaces, rather than the more general functionality of your remove-trailing-char template) you could try a divide-and-conquer approach like this:
Find the mid-point of the string. If the rhs is all spaces, make a recursive call to process the lhs. Otherwise, copy the lhs and make a recursive call to process the rhs. The test whether a string is all spaces is not(normalize-space($X)).
This gives you a max recursive depth of log(N) where N is the string length.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
|