return;
}
my $xsltdoc = $xsltparser->parsefile($input);
unless ($xsltdoc) {
print STDERR "ERROR: cannot parse the XSL input file $input\n";
return;
}
if (ref($namespace) eq HASH_REFERENCE) {
my %nstable = %$namespace;
foreach my $k (keys(%nstable)) {
setXSLtoRelease($self, $k, $nstable{$k}, $xsltdoc);
}
} else {
setXSLtoRelease($self, $namespace, XML_NS_ATTRIBUTE, $xsltdoc);
}
$xsltdoc->printToFile($output);
return $output;
}
sub setXSLtoRelease
{
my ($self, $xslns, $xmlns, $xsltdoc) = @_;
my $nselem = get_first_element_with_attribute($self, $xmlns);
my $dfns = $nselem->getAttribute($xmlns) if $nselem;
if ($dfns) {
$nselem = get_first_element_with_attribute($xsltdoc, $xslns);
return unless $nselem;
$nselem->setAttribute($xslns, $dfns);
return;
}
# if there is no instance of the specified namespace in the xml doc,
# make sure the prefix is removed from the xsl file. This is for backward
# compatiblitiy. Some of the JUNOScript Responses from older
# releases do not have the default namespace. The XSL file would
# not work with it unless we make this change.
my ($declare, $prefix) = split(/:/, $xslns);
$self->remove_prefix_from_element($xsltdoc, $prefix);
}
1;
__END__
=head1 NAME
JUNOS::Response - Response object from a remote Juniper box
=head1 SYNOPSIS
This example retrieves 'show chassis hardware' information and transforms
the input with XSLT. A JUNOS::Response object is returned by the
$jnx->get_chassis_inventory() call.
use JUNOS::Device;
# connect TO the JUNOScript server
$jnx = new JUNOS::Device(hostname => "router11",
login => "johndoe",
password => "secret",
access => "telnet");
unless ( ref $jnx ) {
die "ERROR: $deviceinfo{hostname}: can't connect.\n";
}
# send the command and receive a XML::DOM object
my $res = $jnx->get_chassis_inventory(detail => 1);
unless ( ref $res ) {
die "ERROR: $deviceinfo{hostname}: can't execute command $query.\n";
}
# Check and see if there were any errors in executing the command.
# If all is well, output the response using XSLT.
my $err = $res->getFirstError();
if ($err) {
print STDERR "ERROR: $deviceinfo{'hostname'} - ", $err->{message}, "\n";
} else {
#
# Now do the transformation using XSLT.
#
my $xmlfile = "$deviceinfo{hostname}.xml";
$res->printToFile($xmlfile);
my $nm = $res->translateXSLtoRelease('xmlns:lc', $xslfile, "$xslfile.tmp");
if ($nm) {
my $command = "xsltproc $nm $deviceinfo{hostname}.xml";
system($command);
} else {
print STDERR "ERROR: Invalid XSL File $xslfile\n";
}
}
# always close the connection
$jnx->request_end_session();
$jnx->disconnect();
=head1 DESCRIPTION
=3= |