diff options
Diffstat (limited to 'boom')
-rw-r--r-- | boom/test.pl | 55 | ||||
-rw-r--r-- | boom/test.xml | 4 | ||||
-rw-r--r-- | boom/test.xsl | 27 |
3 files changed, 86 insertions, 0 deletions
diff --git a/boom/test.pl b/boom/test.pl new file mode 100644 index 0000000..c3ecb42 --- /dev/null +++ b/boom/test.pl @@ -0,0 +1,55 @@ +#!/usr/bin/perl +use strict; +use warnings; +use XML::LibXML; +use XML::LibXSLT; +use open ':std',':locale'; + +my $tmpdoc=XML::LibXML->createDocument(); +{my $el=$tmpdoc->createElement('doc'); +$tmpdoc->setDocumentElement($el); +my $e1=$tmpdoc->createElement('test'); +$e1->appendTextNode('blah balh'); +$el->appendChild($e1); +} +my $doc_mem=XML::LibXML->createDocument(); +{my $el=$doc_mem->createElement('test'); +$doc_mem->setDocumentElement($el); +my $e1=$doc_mem->createElement('some'); +$el->appendChild($e1); +} + +my $NS='urn:test'; +{ +my $p=XML::LibXML->new(); +my $t=XML::LibXSLT->new(); + +$t->register_function($NS,'doc',\&test_doc); +$t->register_function($NS,'str',\&test_str); +$t->debug_callback(sub{print@_}); + +my $doc=$p->parse_file('test.xml'); +my $st=$t->parse_stylesheet_file('test.xsl'); + +my $out=$st->transform($doc); +print $st->output_as_chars($out); +$out=$st->transform($doc_mem); +print $st->output_as_chars($out); +} + +sub test_doc { + my $odoc=XML::LibXML::Document->new(); + my $el=$odoc->createElementNS($NS,'doc'); + $odoc->setDocumentElement($el); + $el->appendTextNode('a test'); + $el->appendChild($odoc->importNode( + ($tmpdoc->findnodes('/doc/test'))[0])); + $el->appendChild($odoc->importNode( + ($doc_mem->findnodes('/test'))[0])); + warn('returning from test_doc'); + return $odoc; +} + +sub test_str { + return 'a string'; +} diff --git a/boom/test.xml b/boom/test.xml new file mode 100644 index 0000000..c13808a --- /dev/null +++ b/boom/test.xml @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> +<doc> + <test id="5">testo</test> +</doc>
\ No newline at end of file diff --git a/boom/test.xsl b/boom/test.xsl new file mode 100644 index 0000000..ea32419 --- /dev/null +++ b/boom/test.xsl @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="utf-8"?> +<x:stylesheet xmlns:x="http://www.w3.org/1999/XSL/Transform" + version="1.0" + xmlns:t="urn:test" + exclude-result-prefixes="t" + > + + <x:output method="xml" encoding="utf-8"/> + + <x:template match="/doc|/test"> + <out> + <from-func><x:value-of select="t:str()"/></from-func> + <from-func><x:apply-templates select="t:doc()"/></from-func> + <x:apply-templates/> + </out> + </x:template> + + <x:template match="*"> + <x:copy> + <x:apply-templates select="@*|*"/> + </x:copy> + </x:template> + <x:template match="@*"> + <x:copy/> + </x:template> + +</x:stylesheet>
\ No newline at end of file |