Subject: RE: [xsl] String match within block of text From: "Jarno Elovirta" <jarno@xxxxxxxxxxxxxx> Date: Thu, 19 Apr 2001 15:13:58 +0300 |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] String match within block of , Tanzila Mohammad | Thread | Re: [xsl] String match within block, Jeni Tennison |
Re: [xsl] Transform min and max val, Jeni Tennison | Date | [xsl] Transformation of generic spr, Xiaocun Xu |
Month |