[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Re: [xsl] String manipulation XSLT 1.0
Subject: Re: [xsl] String manipulation XSLT 1.0 From: pankaj.c@xxxxxxxxxxxxxxxxxx Date: Fri, 24 Sep 2010 16:26:33 +0530 |
>What do you mean "all spaces"? It only removes leading and trailing >spaces, and duplicate spaces, but it will leave a space between two >non-space characters if there was at least one... If you read my original post or whole thread it says I have an element, Input ==== <given-name>A.H.</given-name> Output ==== <given-name>A. H.</given-name> <!-- Notice the space after A. --> Martin has given a nice solution for it and almost fits the bill except I do not need space after "." in last initial. The best I have done is below. Only the issue with <xsl:template name="replace-substring"> which adds space even after the last initial. So if I use normalize-space() it removes the extra space added by template or MIGHT POSSIBLE I AM NOT CORRECTLY USING IT. Hope this makes myself clear. <xsl:template match="given-name"> <xsl:copy> <xsl:choose> <xsl:when test="string-length(.)=2 and contains(.,'.')"> <xsl:value-of select="."/> </xsl:when> <xsl:when test="string-length(.)=4 and contains(.,'.')"> <xsl:value-of select="concat(substring-before(., '.'), '. ', substring-after(., '.'))"/> </xsl:when> <xsl:otherwise> <xsl:call-template name="replace-substring"> <xsl:with-param name="original" select="."/> <xsl:with-param name="substring" select="'.'"/> <xsl:with-param name="replacement" select="'. '"/> </xsl:call-template> </xsl:otherwise> </xsl:choose> </xsl:copy> </xsl:template> <xsl:template name="replace-substring"> <xsl:param name="original"/> <xsl:param name="substring"/> <xsl:param name="replacement" select="'. '"/> <xsl:choose> <xsl:when test="contains($original, $substring)"> <xsl:value-of select="substring-before($original, $substring)"/> <xsl:copy-of select="$replacement"/> <xsl:call-template name="replace-substring"> <xsl:with-param name="original" select="substring-after($original, $substring)"/> <xsl:with-param name="substring" select="$substring"/> <xsl:with-param name="replacement" select="$replacement"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$original"/> </xsl:otherwise> </xsl:choose> </xsl:template>
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] String manipulation XSLT , Emmanuel Bégué | Thread | Re: [xsl] String manipulation XSLT , Emmanuel Bégué |
Re: [xsl] String manipulation XSLT , Emmanuel Bégué | Date | Re: [xsl] String manipulation XSLT , Emmanuel Bégué |
Month |