[xsl] Recursively Processing Text Question

Subject: [xsl] Recursively Processing Text Question
From: Matthew Broude <mbroude@xxxxx>
Date: Sun, 04 Dec 2005 03:04:15 -0500
Hello all -

I'm in the middle of a big project and I'm getting tripped up by something
that seems like it should be fairly simple....

I am working with an XML file of news stories that includes a list of
keywords to use as links, essentially in a format like:

<LINK>Term 1</LINK>
<LINK>Term 2</LINK>
<LINK>Term 3</LINK>

I am trying to recursively add links in around the first occurrence in
FULLTEXT of each keyword specified in the LINKs. Here's the XSL template
I've written so far:

<xsl:template name="TextLinker">
    <xsl:param name="LinkNum" select="count(LINK) + 1"/>
        <xsl:when test="$LinkNum > count(LINK)">
            <xsl:value-of select="FULLTEXT"/>
            <xsl:variable name="LinkedText">
                <xsl:call-template name="TextLinker">
                    <xsl:with-param name="LinkNum" select="$LinkNum + 1"/>
            <xsl:variable name="LinkText"><xsl:value-of
             <xsl:variable name="PreLinkText"
select="substring-before($LinkedText, $LinkText)"/>
             <xsl:variable name="PostLinkText"
select="substring-after($LinkedText, $LinkText)"/>
          <xsl:value-of select="$PreLinkText"/>
             <xsl:value-of select="$PostLinkText"/>

And I call that when I need it by using:

<xsl:call-template name="TextLinker">
<xsl:with-param name="LinkNum" select="1"/>

The end result is that I get back the FULLTEXT with the first LINK keyword
linked properly but with the remaining LINK keywords unchanged. Through
testing of this I know it's looping correctly, it's just seems to end up
returning the untreated FULLTEXT each recursion until it finally resolves
and deals just with LINK[1], thus why the first keyword is linked properly
but the others aren't.

I'm sure it must be something obvious I'm missing.

Please help!


Current Thread