You used
Code:
//*[re:test(., "CHAPTER \d", "i")]
which tests for any occurence of the word "chapter" in upper- or lowercase followed by a single number and inside any tag. My XPath expression tests for an uppercase "CHAPTER" followed by one or more numbers inside a span tag, which itself is inside a p tag. Your expression, for whatever reasons, fits four incidences per chapter. Look at the source and figure it out. And look at
the XPath tutorial I linked to earlier.