Re: [xsl] Replace Special Characters: return, blank and tab

Subject: Re: [xsl] Replace Special Characters: return, blank and tab
From: David Carlisle <davidc@xxxxxxxxx>
Date: Fri, 6 Aug 2004 09:59:29 +0100
> If I called the template only once in my code to only replace the #13, then
> it works fine, the whole node is inserted instead of the text in it.

This means that your input _does_ have #13's in it which means that
one of the following is true:
a) you have a broken XML parser or
b) your input has explicit &#13; in it rather than ends of lines or
c) (Probably this one) your input tree was not made by parsing an XML
   file but built programmatically in a DOM of some sort, and teh #13's
   were forcefully injected into it.

I think your problem is that your are replacing #13 twice. It's the
outermost replacement 9which is fine) but also the innermost one which
has teh following effect you first replace newlines by an element
then you pass the resulting node set back into your template to replace
#9 The first thing your template does with its input $string parameter
is coerce it to be a _string_ ie, throwing away all element nodesand
just keeping is character data:

       <xsl:value-of select="substring-before($string, $pattern)" />

both substring-before and xsl:vale-of would both have that effect, using
both of them doubaly makes sure that you get no eleemnt nodes from this
part, her though you use copy-of

   <xsl:copy-of select="$replacement" />

so the nodes in the replacement are preserved (that is preserved on
output from the template, no nodes in the templates input are
preserved.)

so you just need to do your newline  replacement as the _last_ one (and
figure out why you are getting #13's)

David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

Current Thread