Subject: Re: [xsl] normalize-space() except ... From: "Syd Bauman s.bauman@xxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Tue, 10 Feb 2015 16:56:45 -0000 |
I like what Liam is recommending better than the other solutions (including my own), but I think it is addressing a slightly different problem than what OP posted (at least, slightly different than what I perceive the OP posted -- I could be off. :-), although it may well be the problem OP really *has*. Crism's algorithm addresses the same problem mine does. A quick test says Terry's does, too, although it seems a bit complicated to me.[1] One of the things I like about my "append delimiters, normalize-space(), remove delimiters" approach is that because it uses only simple XPath 1.0 functions, it can be used in XSLT 1.0 and I imagine is very fast. (I think Crism's approach probably has similar advantages.) The following is a complete XSLT 1.0 program that regularizes whitespace as I think the OP was requesting. --------- start --------- <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="text()" priority="1"> <xsl:variable name="intermediate" select="concat('b ', ., 'b ')"/> <xsl:variable name="semifinal" select="normalize-space( $intermediate )"/> <xsl:value-of select="substring( $semifinal, 2, string-length( $semifinal ) -2 )"/> </xsl:template> </xsl:stylesheet> --------- end --------- Note ---- [1] Question -- Terry uses <copy-of> where I use <value-of>. In both cases the select= holds a (variable that is a) string. Is there an advantage of one over the other?
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] normalize-space() except , Terry Badger terry_b | Thread | [xsl] Scope Problems Resulting from, Alex Muir alex@xxxxx |
Re: [xsl] line breaks showing up wi, Michael Kay mike@xxx | Date | [xsl] XSL 1.0 - sum values taken fr, Kevin Bird kevinbria |
Month |