I suspect that lines are passed one by one to the TOC creating code? That would explain the behaviour. Note also the trailing $ at the end of the *matching* regexp that I mentioned in my first post...
I am not sure I understand your magic wand source question - I thought the magic wand is just meant to specify the XPath in a semi-automatic way? Anyway, in case you are asking about the complete XPath I used, then it was this (only trying to catch the first part of chapter name to simplify things):
Code:
//*[re:test(., "^[0-9]+\.\s+[a-zA-Z]+")]
I am going to have a look at the XHTML intermediate, perhaps that will tell me something more...