xsl-list
[Top] [All Lists]

[xsl] Search and replace acronyms

2006-06-23 05:31:52
Hi all :)


I'm using the the following template "replace-acronyms" for finding and replacing acronyms in text parts
of a document.

Exactly more of reusing the text and placing <b> tags around it..

My problem is i need to make a case insensitive search... And use the original text inside <b> tags.

What modifications does my template require?


<xsl:template match="result">
                <a class="big">
<xsl:attribute name="href"><xsl:value-of select="showurl"/></xsl:attribute>
                        <xsl:value-of select="title"/>
                </a>
                <div class="articlePar">
                        <xsl:call-template name="replace-acronyms">
                                <xsl:with-param name="text" select="dynamicsmell" 
/>
                                <xsl:with-param name="acronyms" select="match" 
/>
                        </xsl:call-template>

                </div>
        </xsl:template>

<xsl:template name="replace-acronyms">
<xsl:param name="acronyms" select="." />
<xsl:param name="text" />
<xsl:choose>
  <xsl:when test="not($acronyms)">
    <xsl:value-of select="$text" />
  </xsl:when>
  <xsl:when test="not(string($text))" />
        <xsl:otherwise>
                <xsl:variable name="acronym" select="$acronyms[1]" />
                <xsl:choose>

                        <xsl:when test="contains($text, $acronym)">
<xsl:variable name="before" select="substring-before($text, $acronym)" />
                                <xsl:variable name="after" 
select="substring-after($text, $acronym)" />

                                <xsl:call-template name="replace-acronyms">
                                        <xsl:with-param name="text" 
select="$before" />
                                        <xsl:with-param name="acronyms" 
select="$acronyms[position() >  1]" />
                                </xsl:call-template>

                                <acronym title="{$acronyms[1]}">
                                        <b><xsl:value-of select="$acronym" 
/></b>
                                </acronym>

                                <xsl:call-template name="replace-acronyms">
                                        <xsl:with-param name="text" 
select="$after" />
                                        <xsl:with-param name="acronyms" 
select="$acronyms" />
                                </xsl:call-template>
                        </xsl:when>

                        <xsl:otherwise>
                                <xsl:call-template name="replace-acronyms">
                                <xsl:with-param name="text" select="$text" />
                                <xsl:with-param name="acronyms" 
select="$acronyms[position() >  1]" />
                        </xsl:call-template>

                </xsl:otherwise>
                </xsl:choose>
        </xsl:otherwise>
</xsl:choose>
</xsl:template>


Part of my xml document i parse:

<searchresult total="443" first="1" last="50" dbkey="fionia">
<result>
  <score value="2.00"/>
  <title><![CDATA[Kontakt Fionia Bank]]></title>
<showurl><![CDATA[http://www.fioniabank.dk/kontakt/Kontakt_lille/]]></showurl>
  <match>bank</match>
  <match>fionia</match>
<staticsmell><rawstr>psize__##__17062__##____##__pencoding__##__iso-8859-1__##____##__doctype__##__html</rawstr></staticsmell>
  <dynamicsmell>
<![CDATA[ pdf-format. Vedtægter Hent Fionia Banks vedtægter i pdf-format her. Fionia Bank A/S · Vestre Stationsvej 7 · 5100 Odense C. · Telefon 65 20 40 60 E-mail fioniabank(_at_)fioniabank(_dot_)dk · Copyright © 2002 Fionia Bank A/S · Alle rettigheder forbeholdes.
]]></dynamicsmell>
  <dates
    lastmodified="0"    />
</result>

_________________________________________________________________
Ta' på udsalg året rundt på MSN Shopping: http://shopping.msn.dk - her finder du altid de bedste priser


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>
  • [xsl] Search and replace acronyms, søren jepsen <=