xsl-list
[Top] [All Lists]

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

2015-11-23 18:06:05
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
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>