I am trying to display the text content of a Node, if the content of that node matches another node (sibling). Here is the XML:
<MemberId>
<BillingInfo>
<Details>
<Line NUMBER="0">
<ChargeDate>20140605</ChargeDate>
<DueDate>20140605</DueDate>
<TrackingNumber>PR DED</TrackingNumber>
<Description>Account payroll deduction</Description>
<RevCode>SJ1550</RevCode>
<RevDesc>ACCOUNT PAYROLL DEDUCTION</RevDesc>
<SalesAmount>-11.77</SalesAmount>
<ServiceCharge>0.00</ServiceCharge>
<GST>0.00</GST>
<PST>0.00</PST>
<Othertaxes>0.00</Othertaxes>
<Total>-11.77</Total>
<ChitCode>PR DED</ChitCode>
<ChitDate>20140605</ChitDate>
</Line>
<Line NUMBER="1">
<ChargeDate>20140605</ChargeDate>
<DueDate>20140605</DueDate>
<TrackingNumber>03128862</TrackingNumber>
<Description>Mountain Mkt Sales</Description>
<RevCode>SJ1553</RevCode>
<RevDesc>MOUNTAIN MKT SALES</RevDesc>
<SalesAmount>8.99</SalesAmount>
<ServiceCharge>0.00</ServiceCharge>
<GST>0.00</GST>
<PST>0.61</PST>
<Othertaxes>0.00</Othertaxes>
<Total>9.60</Total>
<ChitCode>03128862</ChitCode>
<ChitDate>20140605</ChitDate>
</Line>
</Details>
</BillingInfo>
<Chits>
<Chit>
<Code>03128862</Code>
<Body><![CDATA[
Member#: 0ECHER
Name: *******
Area: *********
Server: JEANNEANE
Chit#: 03128862
Date: June 5 2014
------- ------- ------- ------- -------
1 MINGUA BEEF JER 8.99
------- ------- ------- ------- -------
Sub-Total 8.99
TAX 0.61
------- ------- ------- ------- -------
Chit Total 9.60
MEMBER CHARGE -9.60
]]></Body>
</Chit>
</Chits>
</MemberId>
I am successfully displaying each ChitCode and ChitDate, because they are in the Line[@number] Node. I want to display the Body node that contains the text "Chit#: XXXXXX" where xxxxxx matches Line->ChitCode. Here is my php, it displays the Body, but it displays the first Body for all the line items:
<?php
foreach($Chitquery as $Chit)
{
foreach($Linequery as $Line)
{
echo "<label class='collapse' for='".$Line->ChitCode."-".$Line->ChitDate."'>".$Line->Description."</label>
<input id='".$Line->ChitCode."-".$Line->ChitDate."' type='checkbox'>
<div>";
// Creates hide - show link for each Description item
// Start getting the matching Chit Code from Chit/Body
if ($Chit->Code = $Line->ChitCode)
{
echo $Chit->Body."</div>";
}
else
{
echo " ".$Line->ChitCode."</div>";
} // End If
} //End foreach Linequery
} // End foreach Chitquery
?>
It's the echo $Chit->Body.""; that I need help with, I want to display the Body that contains the value of $Line->ChitCode.
Oh yeah, and the lines are repeating weird, due to improper placement of 'foreach' statements!
Help! Thanks in advance!
UPDATE: I have changed my php code and now I have the hide-show divs working, with no duplicates, but I get 'array' instead of $ChitBody. I cannot figure out how to find the Body node that contains the $Line->ChitCode in $ChitBody = $member->xpath('Chits/Chit/Body[text()="'.$Line->ChitCode.'"] ');
<?php
foreach($Linequery as $Line) {
$ChitCode = $member->Chits->Chit->Code;
$ChitBody = $member->xpath('Chits/Chit/Body[text()="'.$Line->ChitCode.'"] ');
echo "<label class='collapse' for='".$Line->ChitCode."-".$Line->ChitDate."'>".$Line->Description."</label>
<input id='".$Line->ChitCode."-".$Line->ChitDate."' type='checkbox'>"; // Creates hide - show link for each Description item
// Start getting the matching Chit Code from Chit/Body
if ($ChitCode = $Line->ChitCode) {
echo "<div>Code: ".$ChitCode."<br>".$ChitBody."</div>";
} else {
echo "<div>".$Line->ChitCode."</div>";
} // End If
} //End foreachLinequery
?>