At Thu, 05 Jun 2003 09:16:48 +1000, Stuart Guthrie wrote:
> Does anyone know how to strip \n characters using XSL ie stylesheets?
>
> I�m trying to get some newline characters out of some iCalendar data to
> represent the data in PDF format.
I'm far from being experienced with XSLT, but as I understand it
whitespace is fairly nasty to control carefully, since its largely
invisible in XML.
You can do some tweaking with <xsl:strip-space elements="foo bar"/>,
or try creating the text node yourself with something like:
<xsl:template match="text()"><xsl:text><xsl:value-of
select="translate(., '
', ' ')"></xsl:text></xsl:template>
I've no idea how/if you can get a \n in the translate() argument - I'm
just guessing at the syntax.
Most likely it'll be like many other tasks with XSL - you'll need to
pre or post process with some other tool :(
Just as an example, this (untested) perl script would strip all the
newlines from <foo></foo> elements (printing result on stdout):
#!/usr/bin/perl -w
use XML::Twig;
my $t = XML::Twig->new(twig_roots => {foo => \&stripnl},
twig_print_outside_roots => 1);
$t->parsefile('doc.xml');
sub stripnl {
my ($t, $elem) = @_;
my $text = $elem->text;
$text =~ tr/\n//d;
$elem->set_text($text);
$elem->print;
}
I'll leave it up to you to work out which language is most appropriate
for XML manipulation..
--
- Gus
--
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug