Q:

Selecting up to second space / first two words in a text()

I am having trouble getting my head around how to achieve the following. I have gotten this far:
//*[@id="main"]/div[2]/section/div[2]/h1/span[1][starts-with(.,"IDENTIFIER")]/following::span[1]/text()

This will return a response such as:

Foo1 Foo2 Foo3 Foo4

I am trying to make this return only Foo1 & Foo2, where Foo1 & Foo2 can be any length of characters and there may be any number of additional Foo's following them.
I have tried looking at 
substring-before(//*[@id="main"]/div[2]/section/div[2]/h1/span[1][starts-with(.,"IDENTIFIER")]/following::span[1]/text(), ' ')

To extract up to the first space however I have hit a wall in what I am doing wrong.
I am using the xpath within a Scrapy spider. Any help is appreciated

A:

Example with :
<table>
<td>Pierre Paul Jacques Marie Maurice Jeanne</td>
</table>

XPath expression :
substring(//td,1,string-length(substring-before(//td," "))+string-length(substring-before(substring-after(//td," ")," "))+1)

Output :
Pierre Paul

The XPath works in 3 steps. First we get the length of the second term with 3 functions (substring-after, substring-before, and string-length). Space is used as delimiter. Then we get the length of the first term with 2 functions (substring-before and string-length). Space is used as delimiter. Finally  we use susbstring to extract what we need. Syntax : fn(content of the element,starting position for the extraction (1), ending position (length of text1 + length of text2) + 1(space delimiter)).
You can replace //td with your XPath selector (remove the /text() at the end and try to find a shorter expression).

