xsl-list
[Top] [All Lists]

Re: [xsl] Find the next item in a sequence

2020-05-03 13:12:07
Yes, that did work. One curiosity: I have to set a variable for the next
index ($next-index) instead of using position()+1 directly. Why can't I use
position()+1 directly? Thank you very much.

...

            <xsl:variable name="next-index" select="position()+1"/>

            <xsl:choose>

                <xsl:when test="$line-length +
string-length($words[$next-index]) gt $break-count">

...

 

Full template:

 

<xsl:template name="line">

        <xsl:param name="input"/>

        <xsl:param name="break-count" as="xs:integer"/>

        <xsl:variable name="words" select="tokenize($input)"/>

        <xsl:iterate select="$words">

            <xsl:param name="line-length" select="0"/>

            <xsl:param name="break-count" select="$break-count"/>

            <xsl:variable name="next-index" select="position()+1"/>

            <xsl:choose>

                <xsl:when test="$line-length +
string-length($words[$next-index]) gt $break-count">

                    <xsl:value-of select="concat(.,if(position()!=last())
then ' ' else '')"/>

                    <break/>

                    <xsl:next-iteration>

                        <xsl:with-param name="line-length"
select="string-length(.) + 1"/>

                        <xsl:with-param name="break-count"
select="$break-count - 4"/>

                    </xsl:next-iteration>

                </xsl:when>

                <xsl:otherwise>

                    <xsl:value-of select="concat(.,if(position()!=last())
then ' ' else '')"/>

                    <xsl:next-iteration>

                        <xsl:with-param name="line-length"
select="$line-length + string-length(.) + 1"/>

                        <xsl:with-param name="break-count"
select="$break-count"/>

                    </xsl:next-iteration>

                </xsl:otherwise>

            </xsl:choose>

        </xsl:iterate>

    </xsl:template>) 
--~----------------------------------------------------------------
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>