[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Algorithm for splitting a string at a space


Subject: Re: [xsl] Algorithm for splitting a string at a space
From: "Rick Quatro rick@xxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 24 Nov 2015 00:05:59 -0000

In most cases, David's solution would work fine, but for this particular
problem, I need to split the string at the first space beyond the half-way
point of the string. Then I can use the substring function to get each portion
of the string for my formatted output. (This is slightly different from the
specs when I posted the question). So I reworked it to get the position of the
first space past the halfway point of the string. I am using this:

    <xsl:template name="get-split-pos">
        <xsl:param name="string"/>
        <xsl:variable name="center" select="(string-length($string) idiv 2) +
1"/>
        <xsl:variable name="before" select="substring($string,1,$center)"/>
        <xsl:variable name="after" select="substring($string,$center)"/>
        <xsl:value-of select="string-length(substring-before($after,' ')) +
string-length($before)"/>
    </xsl:template>

This seems to be working well for my purposes. Thanks to all that responded.

Rick


Current Thread