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;