Yeah i think they are almost identical except for the stroke of the crank.
I have a 97 535i and have had all of the usual problems that 540 owners have, cooling system, pcv valve, rocker gaskets, water pump, A/C compressor, Auto gearbox, Cam position sensor etc etc.
Good luck with it......
97 e39 535i
78 e21 320i (for sale or part out)
77 Leyland Mini LS
68 Morris Mini Cooper S