Hi Richard, thank you for your fast answer, it works.
Richard E. Rathmann <rrathmann comcast.net> írta:
> The current() function is an XSLT 1.0 extension to
XPath
1.0 and
> therefore not available for use in XML::LibXML (it
does
work, however,
> in XML::LibXSLT).
>
> You can, however, implement your desired functionality
without it
> (untested):
>
> sub xpath {
> my $node = shift;
> my $s = '';
> my nodelist =
$node->findnodes('./ancestor-or-self: ');
> foreach my $node ( nodelist) {
> $s .=
"/".$node->localname."[";
> $s .=
> $node->findvalue('count(preceding-sibling::' .
$node->nodeName . ')+1');
> $s .= "]";
> }
> return $s;
> }
>
> FYI, the reason why the first call to your xpath()
method
didn't trigger
> the same error message as your second call was that
the
libxml2 parser
> most likely optimized your findvalue XPath to first
find
all preceding
> siblings to the current node and found none, so it
didn't
bother
> attempting to apply the predicate expression, thus
triggering an error
> when it came across the "current()"
reference.
>
> HTH,
> Richard
>
>
> Lengyel Róbert wrote:
> > Hi all,
> >
> > what i want to do is get the XPath of a node. But
using the
> > code below i get the error below.
> >
> > Can anyone know the cause of this problem and how
to
solve it?
> >
> > Many thanks,
> > Robi
> >
> > Code:
> >
============================================================
====
> > use strict; use warnings;
> > use XML::LibXML;
> >
> > my $doc =
XML::LibXML->new()->parse_string(<<'EOT');
> > <?xml version="1.0"
encoding="UTF-8"?>
> > <Elements>
> > <Element/>
> > <Element/>
> > </Elements>
> > EOT
> >
> >
> > my $node1 =
$doc->findnodes("/Elements[1]/Element[1]")->
[0];
> > my $node2 =
$doc->findnodes("/Elements[1]/Element[2]")->
[0];
> >
> > print "XPath1 = ",
xpath($node1),"n"; # This works.
> > print "XPath2 = ",
xpath($node2),"n"; # This errors out.
> >
> > sub xpath {
> > my $node = shift;
> > my $s = '';
> > my nodelist =
$node->findnodes('./ancestor-or-self: ');
> > foreach my $node ( nodelist) {
> > $s .=
"/".$node->localname."[";
> > $s .=
> > $node->findvalue('count(preceding-sibling: [name(curren
t())
> > = name()])+1');
> > $s .= "]";
> > }
> > return $s;
> > }
> >
============================================================
====
> >
> > Error
> >
------------------------------------------------------------
----
> > XPath1 = /Elements[1]/Element[1]
> > xmlXPathCompOpEval: function current not found
> > Unregistered function
> > xmlXPathCompiledEval: 1 objects left on the
stack.
> >
------------------------------------------------------------
----
> >
> > Versions
> > libxml2 2.6.27
> > XML::LibXML 1.62
> >
> >
> >
____________________________________________________________
__
> > Kiadós akció az Alexandra Online-nál kedden és
szerdán!
> > 40% engedménnyel vásárolhatja meg az Alexandra
Kiadó
könyveit!
> > http://ad.adverticum.ne
t/b/cl,1,6022,154194,219404/click.prm
> >
> > _______________________________________________
> > Perl-XML mailing list
> > Perl-XML listserv.ActiveState.com
> > To unsubscribe:
http:/
/listserv.ActiveState.com/mailman/mysubs
> >
> >
>
>
____________________________________________________________
__
Kiadós akció az Alexandra Online-nál kedden és szerdán!
40% engedménnyel vásárolhatja meg az Alexandra Kiadó
könyveit!
http://ad.adverticum.ne
t/b/cl,1,6022,154194,219404/click.prm
_______________________________________________
Perl-XML mailing list
Perl-XML listserv.ActiveState.com
To unsubscribe: http:/
/listserv.ActiveState.com/mailman/mysubs
|