This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Recursion logic / coding


>From: "xmlhack ." <xmlhack@hotmail.com>
>To: XSL-List@lists.mulberrytech.com
>Subject: Help with recursion logic / coding
>Date: Mon, 16 Jul 2001 14:53:37 -0000
>Mime-Version: 1.0
>
>Hi all.  I'm trying to build on an example in Kay's XSLT book and I'm having
>some trouble.
>
>I'm passing two parameters to my XSL.  The XSL searches all the text nodes,
>matches the parameters, and outputs the text node with the matched string
>with some extra tagging -- I'm just bolding terms that are passed in the
>parameters.
>
>If parameter one appears in the text node before parameter two, all is well.
>  If parameter one appears after parameter two in the text node, parameter
>two is not "seen" by the XSL the way I need it to be seen.
>
>Example: if my text node is "The reference to Duncan making Macbeth Prince
>of Northumberland is also inaccurate" and I pass $1=Duncan and $2=Macbeth,
>no problems.  If $1=Macbeth and $2=Duncan, Duncan will not be bolded as
>dictated by my XSL.
>
>I'm guessing that my problem is that I have to recurse over the entire text
>node somehow, but every way I've tried it I end up outputting the entire
>text node a second time.
>
>Can someone help or point me in the right direction?  Coding below...
>
>Thanks!
>Mattio
>
><xsl:template name="do-replace">
>	<xsl:param name="text" />
>
>	<xsl:choose>
>	<xsl:when test="contains(translate($text,$upper,$lower),
>translate($1,$upper,$lower))">
>		<xsl:choose>
>		<xsl:when test="$1!=''">
>			<!--length of the text string to be analyzed-->
>			<xsl:param name="length">
>			<xsl:value-of
>select="string-length(substring-before(translate($text,$upper,$lower),
>translate($1,$upper,$lower)))" />
>			</xsl:param>
>
>			<!--length of the search parameter-->
>			<xsl:param name="lengthandstring">
>			<xsl:value-of select="string-length($1)" />
>			</xsl:param>
>
>			<xsl:param name="lengthplusone">
>			<xsl:value-of select="$length + 1" />
>			</xsl:param>
>
>			<!--first portion of text string-->
>			<xsl:value-of select="substring($text,1,$length)" />
>			<span class="searchresult">
>			<xsl:value-of select="$left" />
>			<!--the matched text-->
>			<xsl:value-of
>select="normalize-space(substring($text,$lengthplusone,$lengthandstring))"
>/>
>			<xsl:value-of select="$right" />
>			</span>
>
>			<!--where the next text string should start, as a piece of the current
>string-->
>			<xsl:param name="start">
>			<xsl:value-of select="$length + string-length($1) + 1" />
>			</xsl:param>
>
>			<xsl:call-template name="do-replace">
>				<xsl:with-param name="text" select="substring($text,$start)" />
>			</xsl:call-template>
>		</xsl:when>
>		<xsl:otherwise>
>			<xsl:value-of select="$text" />
>		</xsl:otherwise>
>		</xsl:choose>
>	</xsl:when>
>	<xsl:when test="contains(translate($text,$upper,$lower),
>translate($2,$upper,$lower))">
>		<xsl:choose>
>		<xsl:when test="$2!=''">
>			<xsl:param name="length">
>			<xsl:value-of
>select="string-length(substring-before(translate($text,$upper,$lower),
>translate($2,$upper,$lower)))" />
>			</xsl:param>
>
>			<xsl:param name="lengthandstring">
>			<xsl:value-of select="string-length($2)" />
>			</xsl:param>
>
>			<xsl:param name="lengthplusone">
>			<xsl:value-of select="$length + 1" />
>			</xsl:param>
>
>			<xsl:value-of select="substring($text,1,$length)" />
>			<span class="searchresult">
>			<xsl:value-of select="$left" />
>			<xsl:value-of
>select="normalize-space(substring($text,$lengthplusone,$lengthandstring))"
>/>
>			<xsl:value-of select="$right" />
>			</span>
>
>			<xsl:param name="start">
>			<xsl:value-of select="$length + string-length($2) +1" />
>			</xsl:param>
>
>			<xsl:call-template name="do-replace">
>				<xsl:with-param name="text" select="substring($text,$start)" />
>			</xsl:call-template>
>		</xsl:when>
>		<xsl:otherwise>
>			<xsl:value-of select="$text" />
>		</xsl:otherwise>
>		</xsl:choose>
>	</xsl:when>
>	<xsl:otherwise>
>		<xsl:value-of select="$text" />
>	</xsl:otherwise>
>	</xsl:choose>
></xsl:template>
>
><xsl:template match="*">
>	<xsl:copy>
>	<xsl:copy-of select="@*" />
>	<xsl:apply-templates />
>	</xsl:copy>
></xsl:template>
>
><xsl:template match="text()">
>	<xsl:call-template name="do-replace">
>		<xsl:with-param name="text" select="." />
>	</xsl:call-template>
></xsl:template>
>_________________________________________________________________
>Get your FREE download of MSN Explorer at http://explorer.msn.com


-- 
======================================================================
B. Tommie Usdin                        mailto:btusdin@mulberrytech.com
Mulberry Technologies, Inc.                http://www.mulberrytech.com  
17 West Jefferson Street                           Phone: 301/315-9631
Suite 207                                    Direct Line: 301/315-9634
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML              
======================================================================

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]