Search

Has anyone got a quick method (using XSLT) of doing a search and replace on a body of text to pick out keywords, specified in the XML source, and wrap them in an element?

I’ve read that sometimes, wrapping keywords in your body text with the tag marks them as keywords for search engines.

I have a list of keywords to wrap, being output from a Tag List, and I was wondering if anyone has already done similar before I go re-invent the wheel.

Cheers in advance…

@designermonkey - Have you tried phoque’s search and replace utility? Does that fully meet your criteria?

In the past have used EXSLT’s str:replace template to replace many search strings at once. The great thing is that you can define a node-set of search/replace patterns like this:

    <xsl:variable name="replacements">
        <replacement search="&amp;">&amp;amp;</replacement>
        <replacement search="CO2">CO<sub>2</sub></replacement>
    </xsl:variable>

And then just call the template, passing the replacements as a param:

    <xsl:call-template name="str:_replace">
        <xsl:with-param name="string" select="your-text-node"/>
        <xsl:with-param name="replacements" select="exsl:node-set($replacements)/replacement"/>
    </xsl:call-template>

Thanks guys, I’ll check them both out!

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details