[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Move leading/trailing spaces outside (XSLT 2.0)
Yves Forkl wrote:
Hi Yves, Tokenize is not a good idea, because it removes the tokens. Unless you only need to count how many times there are spaces, which can be expressed as this: count(tokenize(., '^\s+|\s+$')[not(.)]) this will return 1, 2 or 0. matches can be used with template matching, which will give you an option to do whatever you like with it, based on whether there are trailing, leading, no, or both spaces: <xsl:template match="e[matches(., '^\s+')]"> ....<!-- do something with e-node when there are trailing spaces --> You already saw some ways of dealing with it using analyze-string. On many occasions when you want to do something with both matching and non-matching parts, that's the best you can do. If all you care about is replacing these spaces with some other character (like, an nbsp char) and you want to collapse consecutive spaces, there is the following you can do: replace(., '^\s+|\s+$', 'yourspecialcharhere') -- Abel Braaksma
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|