<xsl:template name="left-trim"> <xsl:param name="s" /> <xsl:choose> <xsl:when test="substring($s, 1, 1) = ''"> <xsl:value-of select="$s"/> </xsl:when> <xsl:when test="normalize-space(substring($s, 1, 1)) = ''"> <xsl:call-template name="left-trim"> <xsl:with-param name="s" select="substring($s, 2)" /> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$s" /> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template name="right-trim"> <xsl:param name="s" /> <xsl:choose> <xsl:when test="substring($s, 1, 1) = ''"> <xsl:value-of select="$s"/> </xsl:when> <xsl:when test="normalize-space(substring($s, string-length($s))) = ''"> <xsl:call-template name="right-trim"> <xsl:with-param name="s" select="substring($s, 1, string-length($s) - 1)" /> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$s" /> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template name="trim"> <xsl:param name="s" /> <xsl:call-template name="right-trim"> <xsl:with-param name="s"> <xsl:call-template name="left-trim"> <xsl:with-param name="s" select="$s" /> </xsl:call-template> </xsl:with-param> </xsl:call-template> </xsl:template>
You need to create an account or log in to post comments to this site.