Preventing the war at all
Charles II of Spain died and bequeathed all of his possessions to his half-sister's grandson Philip, duc d'Anjou .
Was there someone Else the Crown could have been bequeathed too ??
That could have meant close ties with France without risk of Succession going to France ? and keeping things Heated yet not going to actual war ?
The original plan was to make the next king of Spain Joseph Ferdinand of Bavaria, whose grandmother, Margaret Teresa of Spain, was the sister of Charles II. He was the prefered candidate primarily because he was neither a Hapsburg nor a bourbon, though his grandfather had been the holy roman emperor (he was also probably the most rightful candidate, but that is another story). However, these plans encountered a minor roadblock when Joseph ferdinand predeceased Charles.
Upon Joseph ferdinand's death, there were two main claims remaining. One was the Bourbon claim of Louis the dauphin, the other that of Leopold, the Holy Roman emperor, Charles's cousin and the husband of his sister. However, giving him the succession poses the same problem that giving Louis the succession did: him inheiriting Spain would reunite the old habsburg empire, a prospect that few looked forward to. In addition, the french claim was (arguably) superior to his. Both Louis and Leopold defered their claims to their children to younger sons (Philip duke of anjou and the Archduke Charles, respectivly), but that didnt change the basic problems inherent in the situation that would evolve were either party given the throne.
There arent that many other claimants, unless you go much farther (i.e. remoter) back or have more of Philip IV's children survive. His only children to survive to adulthood were Charles and his sisters, who became the queen of france and holy roman empress respectivly (their descendent's claims were described above). Philip III had more children reach adulthood, but that doesnt help. Of his sons, only Philip had (legitimate) children, and his two daughters to mature married and were Louis XIV and Leopold's mothers, thus making them more or less irrelevant (although Leopold's best claim comes from his mother, to be fair). In short, the Spanish Habsburgs were fatally lacking in surviving heirs, especially ones not related to Louis or the Austrian Habsburgs.