On Thursday, 28. March 2002 23:10, Joachim Seibert wrote:

[xsp snippet deleted]
>
> Yes, it could work this way, but one problem appears:
> The keywords are taken out of other xml files. There are about 300 xml
> files with 2 ore more keywords. Summa summarum: 600 keywords.
> Phew! That would become a quite big stylesheet!
> How long does it take to parse a page with this stylesheet? ...

This example assumes that your xml replacements file looks like:
<rep>
        <replacement>
                <search>foo</search>
                <replace>http://www.foo.com</replace>
        </replacement
</rep>

If you expect to have few matches, you could use something like this:

<xsl:variable name="replacements" 
select="document('my/replacements.xml')/reps"/>

<xsl:template ...as before...>
        <xsl:for-each select="$replacements/replacement">
                <xsl:choose>
                        <... similar to before, but using ./search and ./replace ...>
                </xsl:choose>
        </xsl:for-each>
</xsl:template>

For many matches (like, a match every 10 words) split string into words and 
search in $replacements.
Shake thoroughly for more than one replacements xml file.

Now, if the results are cacheable well, you won't see much of the performance 
hit because it is only run once. If not, you've got a problem - this solution 
has the benefit that you don't leave the XSLT domain, save one additional 
programming language/system, it is NOT fast. By writing a custom 
Apache::AxKit::Language module you could keep a perl hash of replacements 
(but consider reloading issues), lending for fast lookup. You can search a 
DOM for text nodes and modify them in-place, or you can use SAX, which would 
be the most efficient solution that currently crosses my mind, but which 
would defy current axkit's "pass-the-dom-around-directly" optimization. (Or 
not? Matt?)

If the word list is updated near to never, consider adding marker tags in a 
nightly cron job or upon adding a file to the server, so it only needs to be 
done once.

-- 
CU
        Joerg

PGP Public Key at http://ich.bin.kein.hoschi.de/~trouble/public_key.asc
PGP Key fingerprint = D34F 57C4 99D8 8F16 E16E  7779 CDDC 41A4 4C48 6F94


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to