The is that you're not using the current context inside the predicate, but starting at the root again.
Given you want to query the number of books containing 'J K.', apply contains to the context of all books:
count(//book[contains(., 'J K.')])
If you want to count the number of occurences of tags containing a text node 'J K.', that's easy, too:
count(//*[contains(text(), 'J K.')])
Counting the number of text nodes containing the needle would be easy, too:
count(//text()[contains(., 'J K.')])
Counting the number of occurences of that needle is not possible in XPath 1.0. In XPath 2.0, you would split at occurences of the needle and return the number of occurences minus 1.
count(tokenize(/, 'J K\.'))-1
Remember fn:tokenize()
uses regular expressions, so the dot has to be escaped.