[xslt] Encoding with libxslt
- From: Benat Dagorret <bernard dagorret onecert fr>
- To: xslt gnome org
- Subject: [xslt] Encoding with libxslt
- Date: 13 Apr 2001 21:00:24 +0200
Hi all,
I have been trying to play with libxslt and Matt Sergeants'
XML-LibXSLT perl wrapper (I would like to get a few XML files
translated on-the-fly by a mod_perl enabled Apache httpd) and I
experience some trouble with ISO-8859-1 encoded data.
Does anybody know if libxslt supports encoding? Is it reliable enough
to be used in a production environment?
Thanks a lot,
Bernard
My setup :
- Debian 2.2 GNU/Linux,
- libxml2-2.3.5 (BTW libxml2-2.3.6 doesn't compile, I will have to
investigate this problem too)
- libxslt-0.6.0 (libxslt-0.7.0 needs libxml2-2.3.6)
- XML-LibXSLT-0.96
And my test files :
1. - test.xml
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<?xml-stylesheet href="test.xsl" type="text/xsl"?>
<test lang="fr">
Traitement des caratères accentués, tels que àéèêëïôùû par exemple,
ainsi que de certains codes comme  ,...
</test>
2. - test.xsl
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" encoding="ISO-8859-1" />
<xsl:template match="test">
<html>
<head>
<title>Test</title>
</head>
<body bgcolor="#ffffff" text="#000000">
<p>
<dl>
<dt><b>Methode 1 </b> [<xsl:value-of select="@lang" />]</dt>
<dd><xsl:apply-templates /></dd>
<dt><b>Methode 2 </b> [<xsl:value-of select="@lang" />]</dt>
<dd><xsl:value-of select="text()" /></dd>
</dl>
</p>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
3. - test.pl
#!/usr/bin/perl
use XML::LibXSLT;
use XML::LibXML;
my $xml = XML::LibXML->new();
my $xsl = XML::LibXSLT->new();
my $xml_source = $xml->parse_file('test.xml');
my $xsl_styles = $xml->parse_file('test.xsl');
my $stylesheet, $resultfile;
eval {
$stylesheet = $xsl->parse_stylesheet($xsl_styles);
$resultfile = $stylesheet->transform($xml_source);
# $resultfile = $stylesheet->transform_file('test.xml');
};
if ($@) { &failure($@); }
my $file = "test.html";
open (FILE,">$file");
#print FILE $xml_source->toString(); # check
#print FILE $xsl_styles->toString(); # check
print FILE $stylesheet->output_string($resultfile);
close (FILE);
sub failure {
my ($msg) = shift;
warn "FAILURE: $msg\n";
}
--
Benat Dagorret <bernard dagorret onecert fr>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]