<?php
$cellarbook = simplexml_load_file("CellarBook.xml");

p("/cellar-book/owner",
  $cellarbook->owner);
p("/cellar-book/cellar/wine[quantity<2]",
  $cellarbook->xpath("/cellar-book/cellar/wine[quantity<2]"));
p("/cellar-book/cellar/wine[1]",
  $cellarbook->cellar->wine[0]);
p("//postal-code/..",
  $cellarbook->xpath("//postal-code/..")); 
p("/cellar-book/owner/street",
  $cellarbook->owner->street); 
foreach ($cellarbook->cellar->wine as $w) {
    p("//wine/@code",$w["code"]);
}
foreach ($cellarbook->children("http://www.iro.umontreal.ca/lapalme/wine-catalog")->
              children() as $w){p("//cat:wine/@code",$w["code"]); 
}
p("/cellar-book/cellar/wine[1]/comment",
  $cellarbook->cellar->wine[0]->comment);
$sum=0;
foreach($cellarbook->cellar->wine as $w){
     $sum+=(int)$w->quantity;
}
p("sum(/cellar-book/cellar/wine/quantity)",$sum);

print("for \$w in //wine return 
    concat(\$w/quantity,':',//cat:wine/@code[.=\$w/@code]/../@name)
");
foreach($cellarbook->cellar->wine as $w){
    foreach ($cellarbook->
                children("http://www.iro.umontreal.ca/lapalme/wine-catalog")
                   ->children() as $catw){
        if((string)$w["code"] == (string)$catw["code"]) 
            print($w->quantity.":".$catw["name"]."\n");
    }
}
print("---------------\n");

$cheapFrenchWines=array();
foreach ($cellarbook->children("http://www.iro.umontreal.ca/lapalme/wine-catalog")
              ->children() as $catw){
      if((string)$catw->origin->country=="France" && (int)$catw->price<20)
            array_push($cheapFrenchWines,$catw["name"]);
}
p("//cat:wine[cat:origin/cat:country='France' and cat:price&amp;lt;20]",
  $cheapFrenchWines);

function p($xpath,$sxo){
    print("$xpath\n");
    var_dump($sxo);
    print("---------------\n");
}

?>