% 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:replace(., '&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="replacesubstring.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="replacement">
<xsl:text>\n</xsl:text>
</xsl:with-param>
</xsl:call-template>
</xsl:template>
<?xml version="1.0"?>
<!-- replace function by P McPhee -->
<xsl:stylesheet version="1.0" xmlns:xsl="
http://www.w3.org/1999/XSL/Transform">
<xsl:template name="replace-substring">
<xsl
aram name="prefix"/>
<xsl
aram name="original"/>
<xsl
aram name="substring"/>
<xsl
aram name="replacement" 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($original, $substring), $replacement)"/>
</xsl:with-param>
<xsl:with-param name="original">
<xsl:value-of select="substring-after($original, $substring)"/>
</xsl:with-param>
<xsl:with-param name="substring">
<xsl:value-of select="$substring"/>
</xsl:with-param>
<xsl:with-param name="replacement">
<xsl:value-of select="$replacement"/>
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl
therwise>
<xsl:value-of select="concat($prefix, $original)"/>
</xsl
therwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>