Thank you! Looking back through the man page for XML::XPath I see that I
missed this each of the 4 times I looked at it :)
findnodes($path, [$context])
Returns a list of nodes found by $path, optionally in
context $context. In scalar context returns an
XML::XPath::NodeSet object.
Thanks again!
Riley
----- Original Message -----
From: "Tom Howe" <[EMAIL PROTECTED]>
To: "Riley James" <[EMAIL PROTECTED]>
Sent: Tuesday, July 30, 2002 1:41 AM
Subject: RE: XPathScript and findnodes()
> findnodes returns a list of nodes when called in array context OR a
nodeset
> when called in scalar context.
>
> In your example you put:
>
> my $cnode = findnodes ('//email/configuration');
>
> $cnode is now a nodeset object (XML::XPath::NodeSet) since you have called
> it in scalar context. You cannot then call findnodes() on the nodeset
> object.
>
> What you probably meant was
>
> my ($cnode) = findnodes ('//email/configuration');
>
> OR
>
> my @nodes = findnodes ('//email/configuration');
> my $cnode = shift @nodes;
>
> now $cnode will be an individual Node object.
>
> It would be handy if there was simply a findnode call that returned a
single
> node when called in scalar context.
>
> tom
>
> -----Original Message-----
> From: Riley James [mailto:[EMAIL PROTECTED]]
> Sent: 30 July 2002 09:06
> To: [EMAIL PROTECTED]
> Subject: XPathScript and findnodes()
>
>
> I'm very confused on XPathScript right now. In the AxKit documentation
> (http://www.axkit.org/docs/xpathscript/guide.dkb?section=3) the following
> example is displayed:
>
> <%
> for my $sect1 (findnodes("/article/sect1")) {
> print $sect1->findvalue("title/text()"), "<br>\n";
> for my $sect2 ($sect1->findnodes("sect2")) {
> print " + ", $sect2->findvalue("title/text()"), "<br>\n";
> for my $sect3 ($sect2->findnodes("sect3")) {
> print " + + ", $sect3->findvalue("title/text()"),
> "<br>\n";
> }
> }
> }
> %>
>
> This example makes perfect sense. But it doesn't seem to work that way. My
> xps doc does this:
>
> <%
> my $cnode = findnodes ('//email/configuration');
>
> my @rcpts;
> for my $node ($cnode->findnodes('./recipients/recipient')) {
> push @rcpts, $node->findvalue('text()');
> }
> %>
>
> <html>
> <head>
> <title><%= findvalue('//data/title/text()') %></title>
> </head>
> <body>
> Recipient list: <%= join(', ',@rcpts) %>
> </body>
> </html>
>
> And the error I get is:
>
> [AxKit] [Error] Can't locate object method "findnodes" via package
> "XML::XPath::NodeSet" (perhaps you forgot to load "XML::XPath::NodeSet"?)
at
> /usr/local/odie_www/htdocs/stylesheets/emailprocess.xps line 10.
>
> I understand that the return of findnodes() is XML::XPath::NodeSet. I've
> read the man page on that, which refers me to the man page on
> XML::XPath::XMLParser for how to get around in it, but it seems to be very
> very difficult to pull out what I need. Am I missing something? Is there
> someway to navigate the node list as in this example? Is there something
> different or special about the source XML for the example?
>
> Thanks!
> Riley
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]