Why not simply use a p:split-sequence to isolate the first doc and pipe it into the p:with-param at line 13 ?
I understand your code, but seems slightly convoluted.