Skip to content

Clean up / debug namespace support #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
Revision history for Perl module XML::XPathScript

1.55 June 20, 2018
- Improve namespace support
- Fix a bug where "xmlns:" was duplicated in the top-level element
- Fix a bug that prevented manual switching between XML::XPath and XML::LibXML as the back-end parser

1.54 July 26, 2008
- Fix bugs in stylesheet DocBook2LaTex
- Fix bug in X::X::Processor::B where there is no whitespace
Expand Down
1 change: 1 addition & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,4 @@ examples/docbook2latex.xps
examples/sample-docbook.xml

SIGNATURE Added here by Module::Build
META.json
64 changes: 34 additions & 30 deletions META.yml
Original file line number Diff line number Diff line change
@@ -1,55 +1,59 @@
---
name: XML-XPathScript
version: 1.54
abstract: 'a Perl framework for XML stylesheets'
author:
- 'Yanick Champoux <yanick@cpan.org>'
- 'Dominique Quatravaux <domq@cpan.org> '
- 'Matt Sergeant <matt@sergeant.org>'
abstract: a Perl framework for XML stylesheets
license: artistic
resources:
license: http://opensource.org/licenses/artistic-license.php
requires:
Carp: 0
Clone: 0
Data::Dumper: 0
File::Basename: 0
IO::File: 0
Readonly: 0
Scalar::Util: 0
Symbol: 0
XML::LibXML: 0
build_requires:
File::Find: 0
File::Spec: 0
File::Find: '0'
File::Spec: '0'
configure_requires:
Module::Build: '0.42'
dynamic_config: 1
generated_by: 'Module::Build version 0.4224, CPAN::Meta::Converter version 2.150010'
license: artistic
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: '1.4'
name: XML-XPathScript
provides:
XML::XPathScript:
file: lib/XML/XPathScript.pm
version: 1.54
version: '1.55'
XML::XPathScript::Processor:
file: lib/XML/XPathScript/Processor.pm
version: 1.54
version: '1.55'
XML::XPathScript::Processor::B:
file: lib/XML/XPathScript/Processor/B.pm
version: 1.54
version: '1.55'
XML::XPathScript::Processor::LibXML:
file: lib/XML/XPathScript/Processor/LibXML.pm
version: 1.54
version: '1.55'
XML::XPathScript::Processor::XPath:
file: lib/XML/XPathScript/Processor/XPath.pm
version: 1.54
version: '1.55'
XML::XPathScript::Stylesheet::DocBook2LaTeX:
file: lib/XML/XPathScript/Stylesheet/DocBook2LaTeX.pm
version: 1.54
version: '1.55'
XML::XPathScript::Template:
file: lib/XML/XPathScript/Template.pm
version: 1.54
version: '1.55'
XML::XPathScript::Template::Content:
file: lib/XML/XPathScript/Processor.pm
XML::XPathScript::Template::Tag:
file: lib/XML/XPathScript/Template/Tag.pm
version: 1.54
generated_by: Module::Build version 0.280801
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.2.html
version: 1.2
version: '1.55'
requires:
Carp: '0'
Clone: '0'
Data::Dumper: '0'
File::Basename: '0'
IO::File: '0'
Readonly: '0'
Scalar::Util: '0'
Symbol: '0'
XML::LibXML: '0'
resources:
license: http://opensource.org/licenses/artistic-license.php
version: '1.54'
x_serialization_backend: 'CPAN::Meta::YAML version 0.018'
19 changes: 11 additions & 8 deletions Makefile.PL
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
# Note: this file was auto-generated by Module::Build::Compat version 0.2808_01
# Note: this file was auto-generated by Module::Build::Compat version 0.4224

unless (eval "use Module::Build::Compat 0.02; 1" ) {
print "This module requires Module::Build to install itself.\n";

require ExtUtils::MakeMaker;
my $yn = ExtUtils::MakeMaker::prompt
(' Install Module::Build now from CPAN?', 'y');

unless ($yn =~ /^y/i) {
die " *** Cannot install without Module::Build. Exiting ...\n";
}

require Cwd;
require File::Spec;
require CPAN;

# Save this 'cause CPAN will chdir all over the place.
my $cwd = Cwd::cwd();

CPAN::Shell->install('Module::Build::Compat');
CPAN::Shell->expand("Module", "Module::Build::Compat")->uptodate
or die "Couldn't install Module::Build, giving up.\n";

chdir $cwd or die "Cannot chdir() back to $cwd: $!";
}
eval "use Module::Build::Compat 0.02; 1" or die $@;
use lib '_build/lib';
Module::Build::Compat->run_build_pl(args => \@ARGV);
my $build_script = 'Build';
$build_script .= '.com' if $^O eq 'VMS';
exit(0) unless(-e $build_script); # cpantesters convention
require MyModuleBuilder;
Module::Build::Compat->write_makefile(build_class => 'MyModuleBuilder');
4 changes: 2 additions & 2 deletions lib/XML/XPathScript.pm
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,9 @@ use File::Basename;
use XML::XPathScript::Processor;
use XML::XPathScript::Template;

our $VERSION = '1.54';
our $VERSION = '1.55';

$XML_parser = 'XML::LibXML';
our $XML_parser = 'XML::LibXML';

my %use_parser = (
'XML::LibXML' => 'use XML::LibXML',
Expand Down
6 changes: 3 additions & 3 deletions lib/XML/XPathScript/Processor.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use base qw/ Exporter /;
use XML::XPathScript::Template;
use Readonly;

our $VERSION = '1.54';
our $VERSION = '1.55';

our @EXPORT = qw/
$DO_SELF_AS_CHILD
Expand Down Expand Up @@ -632,7 +632,7 @@ sub translate_comment_node {
sub start_tag {
my( $self, $node, $name ) = @_;

$name ||= $self->get_node_name( $node ) or return;
$name ||= $self->get_qualified_name( $node ) or return;

my $string = '<'.$name;

Expand All @@ -653,7 +653,7 @@ sub start_tag {

sub end_tag {
my $self = shift;
if (my $name = $_[1] || $self->get_node_name( $_[0] ) ) {
if (my $name = $_[1] || $self->get_qualified_name( $_[0] ) ) {
return "</$name>";
}
return '';
Expand Down
4 changes: 3 additions & 1 deletion lib/XML/XPathScript/Processor/B.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package XML::XPathScript::Processor::B;

use base qw/ XML::XPathScript::Processor /;

our $VERSION = '1.54';
our $VERSION = '1.55';

# No namespaces here
sub get_namespace { }
Expand All @@ -31,6 +31,8 @@ sub to_string {

sub get_node_name { $_[1]->get_name }

sub get_qualified_name { $_[1]->get_name }

sub get_attributes {
if ( $_[1]->can( 'get_attr_names' ) ) {
return map { ( [ $_ => $_[1]->get_attr_value( $_ ) ] )
Expand Down
21 changes: 11 additions & 10 deletions lib/XML/XPathScript/Processor/LibXML.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use warnings;

use base qw/ XML::XPathScript::Processor /;

our $VERSION = '1.54';
our $VERSION = '1.55';

sub get_namespace {
my $ns = $_[1]->getNamespaces();
Expand All @@ -19,18 +19,19 @@ sub is_text_node {
&& !$_[1]->isa('XML::LibXML::Comment');
}

sub get_attributes { return $_[1]->attributes }
sub get_text_content { return $_[1]->textContent }
sub get_child_nodes { return $_[1]->childNodes }
sub get_node_name { return $_[1]->localname }
sub is_element_node { return $_[1]->isa( 'XML::LibXML::Element' ); }
sub is_comment_node { return $_[1]->isa( 'XML::LibXML::Comment' ); }
sub is_pi_node { return $_[1]->isa( 'XML::LibXML::PI' ); }
sub is_nodelist { return $_[1]->isa( 'XML::LibXML::NodeList' ); }
sub get_attributes { return $_[1]->attributes }
sub get_text_content { return $_[1]->textContent }
sub get_child_nodes { return $_[1]->childNodes }
sub get_node_name { return $_[1]->localname }
sub get_qualified_name { return $_[1]->nodeName }
sub is_element_node { return $_[1]->isa( 'XML::LibXML::Element' ); }
sub is_comment_node { return $_[1]->isa( 'XML::LibXML::Comment' ); }
sub is_pi_node { return $_[1]->isa( 'XML::LibXML::PI' ); }
sub is_nodelist { return $_[1]->isa( 'XML::LibXML::NodeList' ); }

sub get_attribute {
return $_[1]->isa( 'XML::LibXML::Namespace' )
? ' xmlns:' . $_[1]->getName() . q{="} . $_[1]->value() . q{" }
? sprintf(q{ %s="%s"}, $_[1]->getName(), $_[1]->value())
: $_[1]->toString( 0, 1 )
;
}
Expand Down
23 changes: 12 additions & 11 deletions lib/XML/XPathScript/Processor/XPath.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,23 @@ package XML::XPathScript::Processor::XPath;

use base qw/ XML::XPathScript::Processor /;

our $VERSION = '1.54';
our $VERSION = '1.55';

sub get_namespace {
my $prefix = $_[1]->getPrefix or return;
return $_[1]->getNamespace( $prefix )->getExpanded();
}

sub get_attributes { $_[1]->getAttributeNodes }
sub get_text_content { $_[1]->getData }
sub get_child_nodes { $_[1]->getChildNodes }
sub get_node_name { $_[1]->getName && $_[1]->getLocalName }
sub is_element_node { $_[1]->isa( 'XML::XPath::Node::Element' ); }
sub is_text_node { $_[1]->isa( 'XML::XPath::Node::Text' ); }
sub is_comment_node { $_[1]->isa( 'XML::XPath::Node::Comment' ); }
sub is_pi_node { $_[1]->isa( "XML::XPath::Node::PI" ); }
sub is_nodelist { $_[1]->isa( 'XML::XPath::NodeSet' ); }
sub get_attribute { $_[1]->toString }
sub get_attributes { $_[1]->getAttributeNodes }
sub get_text_content { $_[1]->getData }
sub get_child_nodes { $_[1]->getChildNodes }
sub get_node_name { $_[1]->getName && $_[1]->getLocalName }
sub get_qualified_name { $_[1]->getName }
sub is_element_node { $_[1]->isa( 'XML::XPath::Node::Element' ); }
sub is_text_node { $_[1]->isa( 'XML::XPath::Node::Text' ); }
sub is_comment_node { $_[1]->isa( 'XML::XPath::Node::Comment' ); }
sub is_pi_node { $_[1]->isa( "XML::XPath::Node::PI" ); }
sub is_nodelist { $_[1]->isa( 'XML::XPath::NodeSet' ); }
sub get_attribute { $_[1]->toString }

1;
2 changes: 1 addition & 1 deletion lib/XML/XPathScript/Stylesheet/DocBook2LaTeX.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use strict;
use XML::XPathScript::Processor;
use Carp;

our $VERSION = '1.54';
our $VERSION = '1.55';

our $processor;

Expand Down
2 changes: 1 addition & 1 deletion lib/XML/XPathScript/Template.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use Scalar::Util qw/ refaddr /;
use overload '&{}' => \&_overload_func,
q{""} => \&_overload_quote;

our $VERSION = '1.54';
our $VERSION = '1.55';

sub new {
my( $class ) = @_;
Expand Down
2 changes: 1 addition & 1 deletion lib/XML/XPathScript/Template/Tag.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use Scalar::Util qw/ reftype /;
use overload '&{}' => \&_overload_func,
q{""} => \&_overload_quote;

our $VERSION = '1.54';
our $VERSION = '1.55';

our @ALLOWED_ATTRIBUTES = qw{
pre post
Expand Down
2 changes: 1 addition & 1 deletion script/xpathscript
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use Symbol;
use File::Basename;
use Carp;

my $VERSION = '1.54';
my $VERSION = '1.55';

my ( $query, $interpolate );
GetOptions( 'query=s' => \$query,
Expand Down
27 changes: 27 additions & 0 deletions t/19namespace.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use strict;
use warnings;

use Test::More "no_plan"; # I, for one, don't like it when a plan
# comes together

use XML::XPathScript;

my $xps = XML::XPathScript->new;

my $noop_stylesheet = '<%= apply_templates() %>';
my $result = $xps->transform( <<'NAMESPACED_XML', $noop_stylesheet);
<rss xmlns:excerpt="http://wordpress.org/export/1.2/excerpt/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wp="http://wordpress.org/export/1.2/" version="2.0">
<channel>
<title>Geography Channel</title>
<wp:wxr_version>1.2</wp:wxr_version>
</channel>
</rss>
NAMESPACED_XML

my ($rss_attributes) = $result =~ m/^<rss ([^>]*)>/;
my @rss_attributes = split m/ /, $rss_attributes;
is scalar(grep { $_ eq 'version="2.0"' } @rss_attributes), 1;
is scalar(grep { $_ =~ m/^xmlns:/ } @rss_attributes), 3;
unlike $result, qr{xmlns:xmlns:};
like $result, qr{<wp:wxr_version>1.2</wp:wxr_version>};
like $result, qr{<title>Geography Channel</title>};