made xpath detection more robust by using the earliest ID in the parent tree when available.