Use parentheses:
(/AppXmlLogWritter/LogData[LogApplication[starts-with(. , 'P')]])[position()<=3]
If you put the position test inside the LogData
predicate then it applies just to that location step and will restrict the match to those LogData
elements that are the first, second or third LogData
child of their respective parent elements. With the parentheses you're constructing an initial node set (of all the LogData
elements whose LogApplication
starts with P) and then selecting the first three nodes from that set in document order.