Topic: Trouble with repeated call-templates Pages that link to <a href="https://ozoneasylum.com/backlink?for=23004" title="Pages that link to Topic: Trouble with repeated call-templates" rel="nofollow" >Topic: Trouble with repeated call-templates\

 
Author Thread
bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

IP logged posted posted 08-20-2004 22:24 Edit Quote

So I have the following two named templates. What I am trying to do is highlight seperate terms from the search. The problem is that while highlightThisTerm works when called by itself, when I call it from within highlightSearchTerms the span tag disappears.

(this part)

code:
<span class="highlightTerm">
<xsl:value-of select="$term" disable-output-escaping="yes" />
</span>




Now I still get the value of $term and if I do something like

code:
hi
<span class="highlightTerm">here
<xsl:value-of select="$term" disable-output-escaping="yes" />doh
</span>
test



Then all the text shows up but still no span tag. Anyone have any ideas why?


code:
<xsl:template name="highlightSearchTerms">
<xsl:param name="haystack" />
<xsl:param name="i" select="1" />

<xsl:variable name="newhaystack">
<xsl:choose>
<xsl:when test="$i &lt;= count(/*/Time_Window/Term)">
<xsl:call-template name="highlightThisTerm">
<xsl:with-param name="haystack" select="$haystack" />
<xsl:with-param name="needle" select="/*/Time_Window/Term" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$haystack" />
</xsl:otherwise>
</xsl:choose>

</xsl:variable>

<xsl:choose>
<xsl:when test="$i &lt; count(/*/Time_Window/Term)">
<xsl:call-template name="highlightSearchTerms">
<xsl:with-param name="haystack" select="$newhaystack" />
<xsl:with-param name="i" select="$i + 1" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$newhaystack" disable-output-escaping="yes"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>




<xsl:template name="highlightThisTerm">

<xsl:param name="haystack" />
<xsl:param name="needle" />

<xsl:variable name="before-length">
<xsl:value-of select="string-length(substring-before( translate($haystack,$UPPERCASE,$LOWERCASE) , translate($needle, $UPPERCASE,$LOWERCASE )))" />
</xsl:variable>

<xsl:variable name="before">
<xsl:value-of select="substring($haystack, 1, $before-length)" />
</xsl:variable>

<xsl:variable name="startPos">
<xsl:value-of select="string-length( $before ) + 1" />
</xsl:variable>
<xsl:variable name="endPos">
<xsl:value-of select="$before-length + 1 + string-length( $needle )" />
</xsl:variable>
<xsl:variable name="term">
<xsl:value-of select="substring($haystack, $startPos, string-length($needle))" />
</xsl:variable>
<xsl:variable name="after">
<xsl:value-of select="substring($haystack, $endPos )" />
</xsl:variable>

<xsl:choose>
<xsl:when test="contains(translate($haystack,$UPPERCASE,$LOWERCASE) , translate($needle, $UPPERCASE,$LOWERCASE ) )">
<xsl:value-of select="$before" />
<span class="highlightTerm">
<xsl:value-of select="$term" disable-output-escaping="yes" />
</span>
<xsl:choose>
<xsl:when test="contains(translate($after,$UPPERCASE,$LOWERCASE) , translate($needle, $UPPERCASE,$LOWERCASE ) )">
<xsl:call-template name="highlightThisTerm">
<xsl:with-param name="haystack" select="$after" />
<xsl:with-param name="needle" select="normalize-space(/*/Search_Term)" />
<!-- <xsl:with-param name="terms" select="normalize-space(/*/Search_Term)" /> -->
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$after" />
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$haystack" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>





.:[ Never resist a perfect moment ]:.



Post Reply
 
Your User Name:
Your Password:
Login Options:
 
Your Text:
Loading...
Options:


« BackwardsOnwards »

Show Forum Drop Down Menu