ND2: fix XML trimming to prevent too much from being removed

Fixes #11998.
Fix loop state parsing

Each loop has a separate valid state flag, so rather than using a global
flag we now set and query each individual loop's flag.
Additional 0-size checking

Fixes #10939
ND2: one more adjustment to loop state parsing

Fixes #10939.
Remove loop state check from FramesBefore/FramesAfter logic
One more fix to position dimension detection

If no stage positions are recorded, assume position count is 1.
Fix stage position check to include non-XML metadata
Prevent NumberFormatException that caused TextInfo dimensions to be ignored
Correct for off-by-ones in SizeZ reporting
Merge pull request #1165 from melissalinkert/rebased/develop/nd2

First round of Nikon ND2 fixes (rebased onto develop)