In article <pa************ *************** *@robertson.net .nz>,
Don Robertson <do*@robertson. net.nz> wrote:
% I am at a loss as how to do this. I am trying
%
% translate($text ,'
','\n')
translate() works on single characters. This will change each new-line
to a back-slash, and do nothing with the n.
You want a `replace' function, but there's none provided in xpath.
When faced with this situation, it's often helpful to visit
http://www.exslt.org and see if there's something there which does
what you want (many XSLT processors support the exslt extensions).
In this case, there's str:replace, so you could have
<xsl:template match='text()' xmlns:str='http ://exslt.org/strings'>
<xsl:value-of select='str:rep lace(., '&xA;', '\n')
</xsl:template>
If that doesn't work, it's possible to create a template which performs
replace operations. I've appended mine below. You use it like this:
<!-- xsl:import must go at the top of the stylesheet -->
<xsl:import href="replacesu bstring.xsl"/>
<xsl:template match='text'()' >
<xsl:call-template name='replace-substring'>
<xsl:with-param name="original" >
<xsl:value-of select="string( .)"/>
</xsl:with-param>
<xsl:with-param name="substring ">
<xsl:text>
 </xsl:text>
</xsl:with-param>
<xsl:with-param name="replaceme nt">
<xsl:text>\n</xsl:text>
</xsl:with-param>
</xsl:call-template>
</xsl:template>
<?xml version="1.0"?>
<!-- replace function by P McPhee -->
<xsl:styleshe et version="1.0" xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:template name="replace-substring">
<xsl:param name="prefix"/>
<xsl:param name="original"/>
<xsl:param name="substring "/>
<xsl:param name="replaceme nt" select="''"/>
<xsl:choose>
<xsl:when test="contains( $original, $substring)">
<xsl:call-template name="replace-substring">
<xsl:with-param name="prefix">
<xsl:value-of select="concat( $prefix, substring-before($origina l, $substring), $replacement)"/>
</xsl:with-param>
<xsl:with-param name="original" >
<xsl:value-of select="substri ng-after($original , $substring)"/>
</xsl:with-param>
<xsl:with-param name="substring ">
<xsl:value-of select="$substr ing"/>
</xsl:with-param>
<xsl:with-param name="replaceme nt">
<xsl:value-of select="$replac ement"/>
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwis e>
<xsl:value-of select="concat( $prefix, $original)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
--
Patrick TJ McPhee
East York Canada
pt**@interlog.c om