You might use XML::XSH2. It's not "another xml module", it's a wrapper around XML::LibXML which makes many things possible. For example, you can use its hash command to hash all the versions by object id, and later use its xsh:lookup function in an XPath expression to retrieve an element from the hash.
open file.xml ;
$version := hash ../id /objects/obj/version ;
ls /objects/obj[ count(refs/id)
and count(refs/id[xsh:lookup('version', .) = ../../ve
+rsion])
= count(refs/id) ];
Update: You can define the same hashing function yourself and solve your problem in the same way:
#!/usr/bin/perl
use warnings;
use strict;
use feature qw{ say };
use XML::LibXML;
use XML::LibXML::XPathContext;
{ my %hash;
sub hash {
my ($var, $dom, $key, $value) = @_;
for my $node ($dom->findnodes($value)) {
$hash{$var}{ $node->findvalue($key) } = $node;
}
}
sub lookup {
my ($var, $key) = @_;
$hash{$var}{$key}
}
}
my $dom = 'XML::LibXML'->load_xml(...);
my $xpc = 'XML::LibXML::XPathContext'->new($dom);
$xpc->registerFunction('lookup', \&lookup);
hash(version => $dom, '../id', '/objects/obj/version');
my @nodes = $xpc->findnodes(
'/objects/obj[ count(refs/id)
and count(refs/id[lookup("version", .) = ../../vers
+ion])
= count(refs/id) ]');
foreach my $node (@nodes) {
say $node->toString(1);
}
map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
|
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
|
|