Your best bet is to get the data layer in pace on the second site, but we don't always have that option.
Assuming that you need to make do, you might try one of these strategies :
Option One :
1) Use one set of data elements that reference the window.digitalData object.
2) Add a bit of code that runs as soon as possible on the page that populates the data layer if it does not exist.
window.digitalData = window.digitalData || {};
window.digitalData.page = window.digitalData.page ||{}
window.digitalData.page.name = window.digitalData.page.name || document.getElementById("WebMIPageName").textContent();
...
Option Two :
Create three data elements for every attribute.
1) Create a data element called "page.name" as a custom JS type with the following code:
return (_satellite.getVar("dl_page.name")||_satellite.getVar("css_page.name"));
2) Create a data element called "dl_page.name" as type JS Object. This would reference digitalData.page.name
3) Create a data element called "css_page.name" as type CSS Selector. #WebMIPageName returning content (as you described above).
In your other rules, reference the data element created in step 1. It will first, try to get a value from dl_page.name. If it does not return a value, then it will attempt to resolve "css_page.name".
Option Three :
As you described, you could put all the logic into a single custom JS data element but as in option one, this would be code heavy.
Here's what that might look like.
Create a data element called "page.name" as a custom JS type with the following code:
return _satellite.getVar("window.digitalData.page.name") || document.getElementById("WebMIPageName").textContent();
This solution uses an undocumented feature of DTM's _satellite.getVar where you can directly access window scoped objects. What's nice is that it will fail gracefully if any part of the referenced object does not exist. This feature has not been moved forward into Launch, so you would have an issue if you wanted to bring these data elements from DTM into Launch at some point.
Option Four, Five, Six
There are other options.
FWIW, My favorite is Option Two.