RE: [xsl] match text node

Subject: RE: [xsl] match text node
From: "Jim Fuller" <jim.fuller@xxxxxxxxxxxxxxxxxx>
Date: Mon, 13 Oct 2003 13:48:58 +0100
-----Original Message-----
From: saigo@xxxxxxxxxxxxx [mailto:saigo@xxxxxxxxxxxxx]
Sent: 13 October 2003 13:11
To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] match text node


I have document like:
       valid html
"valid html" - I mean every html (xml-valid) you can imagine with no
limitation at all. Of course, there are some texts. And there may be
any nodes inside text and so on.

My task: I need to copy whole document (all nodes and all attributes)
but in text nodes I need to delete all &#xA; marks.

try something like this, you need to apply-templates then do an identify transform, your call template naturally matches text() so its fine. I also removed the mode attribute for replace template...not needed.

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="";>
	<xsl:template match="/">
<xsl:template match="@*|node()">
    <xsl:apply-templates select="@*|node()"/>

<xsl:template name="replace" match="text()">
        <xsl:param name="str" select="."/>
        <xsl:param name="search-for" select="'&#xA;'"/>
        <xsl:param name="replace-with">
                <xsl:when test="contains($str,$search-for)">
                        <xsl:value-of select="substring-before($str,$search-for)"/>
                        <xsl:copy-of select="$replace-with"/>
                        <xsl:call-template name="replace">
                                <xsl:with-param name="str" select="substring-after($str,$search-for)"/>
                                <xsl:with-param name="search-for" select="$search-for"/>
                                <xsl:with-param name="replace-with" select="$replace-with"/>
                        <xsl:value-of select="$str"/>

untested, and make sure you look at the raw output to ensure that they have indeed been replaced I would put a visible value in e.g.

        <xsl:param name="replace-with">
        testing testing   <xsl:text/>

good luck, Jim Fuller

 XSL-List info and archive:

Current Thread