[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: String match within block of text

Subject: RE: String match within block of text
From: "Jarno Elovirta" <jarno@xxxxxxxxxxxxxx>
Date: Thu, 19 Apr 2001 15:13:58 +0300
block text selection
Hip hei

> <!-- the aim is to match the species string within synonyms and if they
> match create a url link"

This does the job, but is really really slow...

[c:\temp]type test.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<Genus>
<Species>
         <Specie href="Pf000362.htm">A. ampliceps</Specie>
         <Specie href="Pf000363.htm">A. bivenosa</Specie>
</Species>
<Synonyms> A. ampliceps makes with A. bivenosa a
      complex which also includes A. ligulata, A. salicina and A.
      sclerosperma although the latter three are morphologically quite
      different from the former two and also quite distinct from one
another.
</Synonyms>
</Genus>

[c:\temp]type test.xsl
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="html"
            indent="yes" />

<xsl:variable name="specie" select="Genus/Species/Specie" />

<xsl:template match="/">
  <xsl:apply-templates select="Genus/Synonyms" />
</xsl:template>

<xsl:template match="Synonyms" priority="1">
  <h3>
    <font color="#00007F">
      <i>
        <xsl:value-of select="name()" />
      </i>
    </font>
  </h3>
  <p>
    <font color="#008000">
      <xsl:call-template name="linker">
        <xsl:with-param name="text" select="." />
      </xsl:call-template>
    </font>
  </p>
</xsl:template>

<xsl:template name="linker">
  <xsl:param name="text" />
  <xsl:variable name="match" select="$specie[starts-with($text, .)]" />
  <xsl:if test="$text">
    <xsl:choose>
      <xsl:when test="$match">
        <font color="#008000">
          <i>
            <a href="{$match/@href}">
              <xsl:value-of select="$match" />
            </a>
          </i>
        </font>
        <xsl:call-template name="linker">
          <xsl:with-param name="text" select="substring($text,
string-length($match) + 1)" />
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="substring($text, 1, 1)" />
        <xsl:call-template name="linker">
          <xsl:with-param name="text" select="substring($text, 2)" />
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:if>
</xsl:template>

</xsl:stylesheet>
[c:\temp]saxon test.xml test.xsl
<h3><font color="#00007F"><i>Synonyms</i></font></h3>
<p><font color="#008000"> <font color="#008000"><i><a href="Pf000362.htm">A.
ampliceps</a></i></font> makes with <font color=
"#008000"><i><a href="Pf000363.htm">A. bivenosa</a></i></font> a
            complex which also includes A. ligulata, A. salicina and A.
            sclerosperma although the latter three are morphologically quite
            different from the former two and also quite distinct from one
      another.
      </font></p>

Hope this helps you to come up with a better solution - or just to prove
that you can write faster stylesheets than I can

Jarno - Wolfsheim: Lovesong


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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.