I'm working on a way to assign a variable equal to a filtered path (filtering certain nodes based upon their value in PHP). I'm trying to return the value of the 'Ident' node, when its sibling ('Status') equals "Funded".
In another post related to this project, I got the count of these filtered items (IMSoP's answer), but my aim here is to get the filtered item (node) value for each iteration in a pagination scenario.
Using the count of the filtered items (from that previous post), the pagination code iterates through the filtered items in xml tree data.
Thanks for any leads.
Here is the XML:
<?xml version="1.0" encoding="utf-8"?>
<data>
<record id="1A">
<congrant>
<ident>a</ident>
<status>Not Funded</status>
</congrant>
<congrant>
<ident>b</ident>
<status>Funded</status>
</congrant>
<congrant>
<ident>c</ident>
<status/>
</congrant>
</record>
<record id="1B">
<congrant>
<ident>a</ident>
<status>Not Funded</status>
</congrant>
<congrant>
<ident>b</ident>
<status>Funded</status>
</congrant>
<congrant>
<ident>c</ident>
<status/>
</congrant>
</record>
<record id="1C">
<congrant>
<ident>aaa</ident>
<status>Funded</status>
</congrant>
<congrant>
<ident>bbb</ident>
<status>Funded</status>
</congrant>
<congrant>
<ident>c</ident>
<status>Funded</status>
</congrant>
</record>
</data>
Here is the PHP (for the count of the filtered data):
$url_bio = "test.xml";
$xml_bio = simplexml_load_file($url_bio);
$xml_bio_record=$xml_bio->xpath('//record[@id="1A"]');
$funded_count = 0;
foreach($xml_bio_record as $xb) {
foreach ($xb->congrant as $congrant) {
if ( (string)$congrant->status == 'Funded' ) {
$funded_count++;
}
}
}
Here is what I've tried to get the filtered values to display in the pagination looping. I've simplified the loop somewhat here, to just loop from 0 to the count of filtered items:
$xml_bio_record=$xml_bio->xpath('//record[@id="1A"]');
for ($i = 0; $i <=$funded_count; $i++) {
$strCongrant_ident = $xml_bio_record[0]->xpath('./congrant[$i][status="Funded"]/ident];
echo('<br>$strCongrant_ident is...'.$strCongrant_ident);
}
I've used this loop idea before in a pagination setting, but getting the filter to apply to the variable here is not working - it is not returning the 'ident' node value being a sibling to the matching 'status="Funded"' node. Thanks for any leads.