|
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:
<NEWS>
<STORY>
<FULLTEXT>Article text</FULLTEXT>
<LINK>Term 1</LINK>
<LINK>Term 2</LINK>
<LINK>Term 3</LINK>
</STORY>
<STORY>
...
</STORY>
</NEWS>
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:choose>
<xsl:when test="$LinkNum > count(LINK)">
<xsl:value-of select="FULLTEXT"/>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="LinkedText">
<xsl:call-template name="TextLinker">
<xsl:with-param name="LinkNum" select="$LinkNum + 1"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="LinkText"><xsl:value-of
select="LINK[$LinkNum]"/></xsl:variable>
<xsl:variable name="PreLinkText"
select="substring-before($LinkedText, $LinkText)"/>
<xsl:variable name="PostLinkText"
select="substring-after($LinkedText, $LinkText)"/>
<xsl:value-of select="$PreLinkText"/>
<b><a
href="news.asp?mode=search&terms={$LinkText}"><xsl:value-of
select="$LinkText"/></a></b>
<xsl:value-of select="$PostLinkText"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
And I call that when I need it by using:
<xsl:call-template name="TextLinker">
<xsl:with-param name="LinkNum" select="1"/>
</xsl:call-template>
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!
Thanks!
-Matthew
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] XSLT Processing w/ Embedd, drkm | Thread | [xsl] IQuestion about XSLT and Math, Villani Alessandro |
| [xsl] XSLT Processing w/ Embedded P, Michael B Allen | Date | RE: [xsl] Re: XSLT Transformation ., Michael Kay |
| Month |