On Thursday, 28. March 2002 21:24, Joachim Seibert wrote:
> I got the following task to solve:
>
> In certain tags of my xml files, I want to replace a keyword "foo" with
> some other data (let's say: "bar").
>
> <content>This is foo</content>
> now becomes:
> <content>This is bar</content>

I hope you know a bit XSLT:

<xsl:template match="text()" name="replace">
        <xsl:param name="string" select="."/>
        <xsl:choose>
                <xsl:when test="contains($string,'foo')">
                        <xsl:call-template name="replace">
                                <xsl:param name="string" 
select="substring-before($string,'foo')"/>
                        </xsl:call-template>
                        <a href="http://www.foo.com";>foo</a>
                        <xsl:call-template name="replace">
                                <xsl:param name="string" 
select="substring-after($string,'foo')"/>
                        </xsl:call-template>
                </xsl:when>
                <xsl:when test="contains($string,'bar')">
                        ... like above ...
                </xsl:when>
                <xsl:otherwise>
                        <xsl:value-of select="$string"/>
                </xsl:otherwise>
        </xsl:choose>
</xsl:template>

To have more complicated matching you will have to dig the XSLT expression 
syntax. Also consider adding tags around the affected text for easier 
matching.

-- 
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