ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> perl-xml
perl-xml
Re: simple XML::XPath question
by Lev Lvovsky other posts by this author
Jul 14 2006 3:24PM messages near this date
view in the new Beta List Site
Re: simple XML::XPath question | XML::DOM2
& XSLT On Jul 14, 2006, at 6:51 AM, Thomas, Mark - BLS CTR wrote:

>  You can do much better than that! All you need is one loop.
> 
> 
> > my @DataLists = $xp->findnodes("/CompanyData/Data/Datalist);
> >
> 
>  This is a typical newbie mistake. You've stopped too early. You're not
>  really doing anything with the DataList element itself, right? It's  
>  the
>  children you're interested in. Go straight to them!
> 
>  What you really want are the DataListElementX nodes, or put another  
>  way,
>  the children of DataList following the Id. So that's what we'll loop
>  over:
> 
>  foreach my $elem ($x->findnodes('//DataList/*[preceding- 
>  sibling::Id]')){
> 
>    # Get the Id which is the key to the hash
>    my $Id = $elem->findvalue('preceding-sibling::Id');
> 
>    # Now push it on to the hash as an array element
>    push @{$DataList{$Id}}, $elem->string_value;
>  }
> 

I'm a bit lost on the [preceding-sibling::Id] notation.  The w3 site  
defines "preceding-sibling" as "selects all siblings before the  
current node", what gets (or more specifically how) selected as the  
"current node" with the notation that you've used?


>  That's all you need to do. This is the result:
> 
>  %DataList = (
>    'first' => [' first_element_1 ',' ... ',' ... '],
>    'second' => [' second_element_1 ',' ... ',' ... '],
>    'third' => [' ... ',' ... ',' ... ']
>  );
> 

Yep, looks to work well - my structures are in reality a bit more  
complex, but this is a great starting point.  Thanks for your help!

-lev


_______________________________________________
Perl-XML mailing list
Perl-XML@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Thread:
Lev Lvovsky
Mark - BLS CTR Thomas
Yanick Champoux
Lev Lvovsky

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved