aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2009-08-17 13:48:11 +0200
committerdakkar <dakkar@thenautilus.net>2009-08-17 13:48:11 +0200
commit0aa99246f129a4218464a2ffaecf88aa77dbd22e (patch)
tree75b429fedfb6b8ab39a9d0b41b19f2446989f83b
parentdecode ReST files before parsing (diff)
downloadWebCoso-0aa99246f129a4218464a2ffaecf88aa77dbd22e.tar.gz
WebCoso-0aa99246f129a4218464a2ffaecf88aa77dbd22e.tar.bz2
WebCoso-0aa99246f129a4218464a2ffaecf88aa77dbd22e.zip
some EXSLT functions missing from XML::LibXSLT
untested, and should really be in a separate distribution
-rw-r--r--lib/WebCoso/XSLT.pm3
-rw-r--r--lib/XML/LibXSLT/EXSLT.pm44
2 files changed, 47 insertions, 0 deletions
diff --git a/lib/WebCoso/XSLT.pm b/lib/WebCoso/XSLT.pm
index 28643c5..b52d596 100644
--- a/lib/WebCoso/XSLT.pm
+++ b/lib/WebCoso/XSLT.pm
@@ -8,6 +8,7 @@ use XML::LibXSLT;
use DateTime::Format::Strptime;
use Log::Log4perl ':easy';
use Data::Dumper;
+use XML::LibXSLT::EXSLT;
my $NS='http://webcoso.thenautilus.net/';
@@ -19,6 +20,8 @@ sub new {
$self->{xml_parser}=XML::LibXML->new();
$self->{xslt_proc}=XML::LibXSLT->new();
+ XML::LibXSLT::EXSLT->apply_to($self->{xslt_proc});
+
$self->{xslt_proc}->register_function($NS,'title-for',
sub{$self->getTitleForXML(@_)});
$self->{xslt_proc}->register_function($NS,'dst-uri-for',
diff --git a/lib/XML/LibXSLT/EXSLT.pm b/lib/XML/LibXSLT/EXSLT.pm
new file mode 100644
index 0000000..fce93e9
--- /dev/null
+++ b/lib/XML/LibXSLT/EXSLT.pm
@@ -0,0 +1,44 @@
+package XML::LibXSLT::EXSLT;
+use strict;
+use warnings;
+use XML::LibXML;
+
+my $STRING_NS='http://exslt.org/strings';
+
+my @funcs=(
+ [$STRING_NS,'split',\&estr_split],
+);
+
+sub apply_to {
+ my (undef,$xslt)=@_;
+
+ for my $f (@funcs) {
+ my ($ns,$name,$code)=@$f;
+ $xslt->register_function($ns,$name,$code);
+ }
+ return;
+}
+
+sub estr_split {
+ my ($string,$sep)=@_;
+
+ if (defined $sep) {
+ $sep="$sep";
+ }
+ else {
+ $sep=' ';
+ }
+
+ my @tokens=split /\Q$sep/,"$string";
+ my $doc=XML::LibXML::DocumentFragment->new();
+
+ for my $t (@tokens) {
+ my $e=XML::LibXML::Element->new('token');
+ $e->appendTextNode($t);
+ $doc->appendChild($e);
+ }
+
+ return $doc;
+}
+
+1;