code: public function xpathByAttribute($strXpathQuery, $strIndexAttribute = 'name')
      {
  
          $arrOut = array();
          $objResult = $this->xpath($strXpathQuery);
  
          foreach ($objResult as $intIndex => $objNode) {
              $strIndex = (string)$objNode->attributes()->$strIndexAttribute;
              $arrOut[$strIndex] = $objResult[$intIndex];
          }
  
          return $arrOut;
      }
docs: Execute xpath query and index by attribute
  
  @param string $strXpathQuery
  @param string $strIndexAttribute
  @return static[]