Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • manwood 87 posts 109 karma points
    Mar 31, 2010 @ 10:53
    manwood
    0

    How can I build up a string iteratively in XSLT?

    Hi

    I want to do a for-each over a series of nodes, extract some detail from each node, append the detail onto a string, then finally display the composite string result. Is there an easy way to do this in XSLT?

    Thanks

  • Tommy Poulsen 514 posts 708 karma points
    Mar 31, 2010 @ 11:03
    Tommy Poulsen
    0

    Hi manwood

     

    You would probably want to call templates recursively to build up your string, as you cannot re-assign values to a variable.

    Here is an example of a call-template structure

    <!-- Using call-template -->
    <table><tr><td>
    <xsl:call-template name="Fibonacci">
    <xsl:with-param name="prev" select="1" />
    <xsl:with-param name="next" select="1" />
    <xsl:with-param name="itemsLeft" select="10" />
    </xsl:call-template>
    </td></tr></table>
    </xsl:template>

    <xsl:template name="Fibonacci">
    <xsl:param name="prev"/>
    <xsl:param name="next"/>
    <xsl:param name="itemsLeft"/>

    <xsl:value-of select="$prev"/><br/>

    <xsl:if test="$itemsLeft &gt; 0">
    <xsl:call-template name="Fibonacci">
    <xsl:with-param name="prev" select="$next" />
    <xsl:with-param name="next" select="$prev+$next" />
    <xsl:with-param name="itemsLeft" select="$itemsLeft - 1" />
    </xsl:call-template>
    </xsl:if>
    </xsl:template>

     

    To build up your string you could keep passing on the current string as a parameter in the recursion

    >Tommy

     

     

Please Sign in or register to post replies

Write your reply to:

Draft