From 0aa99246f129a4218464a2ffaecf88aa77dbd22e Mon Sep 17 00:00:00 2001 From: dakkar Date: Mon, 17 Aug 2009 13:48:11 +0200 Subject: some EXSLT functions missing from XML::LibXSLT untested, and should really be in a separate distribution --- lib/WebCoso/XSLT.pm | 3 +++ lib/XML/LibXSLT/EXSLT.pm | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 lib/XML/LibXSLT/EXSLT.pm (limited to 'lib') 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; -- cgit v1.2.3