have this code:
$products = $feed->_xpath->query( "//cf:vehicle" );
foreach( $products as $product )
{
echo $product->nodeName . ': ' . $product->getAttribute('code') . '<br />';
$imgs = $feed->_xpath->query( "//cf:image" , $product );
echo ' Imgs: ' . $imgs->length . '<br />';
}
the number of product nodes found in the xmlfeed is 103 - that is correct.
the query to locat images within that node however is NOT doing so within the current node context - it finds 116 image nodes which is the total number of image nodes within the feed where as it should only select the images within the current product (between 0 and 3 in most cases)
Any pointers muchly appreciated.
You have to use .//cf:image
to make it relative to the context node.
From http://www.w3.org/TR/xpath/#path-abbrev:
//para selects all the para descendants of the document root and thus selects all para elements in the same document as the context node
and
.//para selects the para element descendants of the context node
Also see http://bugs.php.net/bug.php?id=34413
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With