for $art in collection("sortietalismane-slurp_3208.xml")//p for $elt in $art/item let $conc2 := if (($elt/a[4]/text()="NC") and ($elt/following-sibling::item[1]/a[4]/text()="P") and ($elt/following-sibling::item[2]/a[4]/text()="NC") and ($elt/following-sibling::item[3]/a[4]/text()="P")) then ( concat($elt/a[2]/text()," ",$elt/following-sibling::item[1]/a[2]/text()," ",$elt/following-sibling::item[2]/a[2]/text()," ", $elt/following-sibling::item[3]/a[2]/text()) ) else if (($elt/a[4]/text()="NPP") and ($elt/following-sibling::item[1]/a[4]/text()="P") and ($elt/following-sibling::item[2]/a[4]/text()="NC") and ($elt/following-sibling::item[3]/a[4]/text()="P")) then ( concat($elt/a[2]/text()," ",$elt/following-sibling::item[1]/a[2]/text()," ",$elt/following-sibling::item[2]/a[2]/text()," ", $elt/following-sibling::item[3]/a[2]/text()) ) else if (($elt/a[4]/text()="NPP") and ($elt/following-sibling::item[1]/a[4]/text()="P") and ($elt/following-sibling::item[2]/a[4]/text()="NPP")and ($elt/following-sibling::item[3]/a[4]/text()="P")) then ( concat($elt/a[2]/text()," ",$elt/following-sibling::item[1]/a[2]/text()," ",$elt/following-sibling::item[2]/a[2]/text()," ", $elt/following-sibling::item[3]/a[2]/text()) ) else if (($elt/a[4]/text()="NC") and ($elt/following-sibling::item[1]/a[4]/text()="P") and ($elt/following-sibling::item[2]/a[4]/text()="NPP")and ($elt/following-sibling::item[3]/a[4]/text()="P")) then ( concat($elt/a[2]/text()," ",$elt/following-sibling::item[1]/a[2]/text()," ",$elt/following-sibling::item[2]/a[2]/text()," ", $elt/following-sibling::item[3]/a[2]/text()) ) else if (($elt/a[4]/text()="NC") and ($elt/following-sibling::item[1]/a[4]/text()="P+D") and ($elt/following-sibling::item[2]/a[4]/text()="NC") and ($elt/following-sibling::item[3]/a[4]/text()="P")) then ( concat($elt/a[2]/text()," ",$elt/following-sibling::item[1]/a[2]/text()," ",$elt/following-sibling::item[2]/a[2]/text()," ", $elt/following-sibling::item[3]/a[2]/text()) ) else if (($elt/a[4]/text()="NPP") and ($elt/following-sibling::item[1]/a[4]/text()="P+D") and ($elt/following-sibling::item[2]/a[4]/text()="NC") and ($elt/following-sibling::item[3]/a[4]/text()="P")) then ( concat($elt/a[2]/text()," ",$elt/following-sibling::item[1]/a[2]/text()," ",$elt/following-sibling::item[2]/a[2]/text()," ", $elt/following-sibling::item[3]/a[2]/text()) ) else if (($elt/a[4]/text()="NPP") and ($elt/following-sibling::item[1]/a[4]/text()="P=D") and ($elt/following-sibling::item[2]/a[4]/text()="NPP")and ($elt/following-sibling::item[3]/a[4]/text()="P")) then ( concat($elt/a[2]/text()," ",$elt/following-sibling::item[1]/a[2]/text()," ",$elt/following-sibling::item[2]/a[2]/text()," ", $elt/following-sibling::item[3]/a[2]/text()) ) else if (($elt/a[4]/text()="NC") and ($elt/following-sibling::item[1]/a[4]/text()="P+D") and ($elt/following-sibling::item[2]/a[4]/text()="NPP")and ($elt/following-sibling::item[3]/a[4]/text()="P")) then ( concat($elt/a[2]/text()," ",$elt/following-sibling::item[1]/a[2]/text()," ",$elt/following-sibling::item[2]/a[2]/text()," ", $elt/following-sibling::item[3]/a[2]/text()) ) else if (($elt/a[4]/text()="NC") and ($elt/following-sibling::item[1]/a[4]/text()="P") and ($elt/following-sibling::item[2]/a[4]/text()="NC") and ($elt/following-sibling::item[3]/a[4]/text()="P+D")) then ( concat($elt/a[2]/text()," ",$elt/following-sibling::item[1]/a[2]/text()," ",$elt/following-sibling::item[2]/a[2]/text()," ", $elt/following-sibling::item[3]/a[2]/text()) ) else if (($elt/a[4]/text()="NPP") and ($elt/following-sibling::item[1]/a[4]/text()="P") and ($elt/following-sibling::item[2]/a[4]/text()="NC") and ($elt/following-sibling::item[3]/a[4]/text()="P+D")) then ( concat($elt/a[2]/text()," ",$elt/following-sibling::item[1]/a[2]/text()," ",$elt/following-sibling::item[2]/a[2]/text()," ", $elt/following-sibling::item[3]/a[2]/text()) ) else if (($elt/a[4]/text()="NPP") and ($elt/following-sibling::item[1]/a[4]/text()="P") and ($elt/following-sibling::item[2]/a[4]/text()="NPP")and ($elt/following-sibling::item[3]/a[4]/text()="P+D")) then ( concat($elt/a[2]/text()," ",$elt/following-sibling::item[1]/a[2]/text()," ",$elt/following-sibling::item[2]/a[2]/text()," ", $elt/following-sibling::item[3]/a[2]/text()) ) else if (($elt/a[4]/text()="NC") and ($elt/following-sibling::item[1]/a[4]/text()="P") and ($elt/following-sibling::item[2]/a[4]/text()="NPP")and ($elt/following-sibling::item[3]/a[4]/text()="P+D")) then ( concat($elt/a[2]/text()," ",$elt/following-sibling::item[1]/a[2]/text()," ",$elt/following-sibling::item[2]/a[2]/text()," ", $elt/following-sibling::item[3]/a[2]/text()) ) else if (($elt/a[4]/text()="NC") and ($elt/following-sibling::item[1]/a[4]/text()="P+D") and ($elt/following-sibling::item[2]/a[4]/text()="NC") and ($elt/following-sibling::item[3]/a[4]/text()="P+D")) then ( concat($elt/a[2]/text()," ",$elt/following-sibling::item[1]/a[2]/text()," ",$elt/following-sibling::item[2]/a[2]/text()," ", $elt/following-sibling::item[3]/a[2]/text()) ) else if (($elt/a[4]/text()="NPP") and ($elt/following-sibling::item[1]/a[4]/text()="P+D") and ($elt/following-sibling::item[2]/a[4]/text()="NC") and ($elt/following-sibling::item[3]/a[4]/text()="P+D")) then ( concat($elt/a[2]/text()," ",$elt/following-sibling::item[1]/a[2]/text()," ",$elt/following-sibling::item[2]/a[2]/text()," ", $elt/following-sibling::item[3]/a[2]/text()) ) else if (($elt/a[4]/text()="NPP") and ($elt/following-sibling::item[1]/a[4]/text()="P+D") and ($elt/following-sibling::item[2]/a[4]/text()="NPP")and ($elt/following-sibling::item[3]/a[4]/text()="P+D")) then ( concat($elt/a[2]/text()," ",$elt/following-sibling::item[1]/a[2]/text()," ",$elt/following-sibling::item[2]/a[2]/text()," ", $elt/following-sibling::item[3]/a[2]/text()) ) else if (($elt/a[4]/text()="NC") and ($elt/following-sibling::item[1]/a[4]/text()="P+D") and ($elt/following-sibling::item[2]/a[4]/text()="NPP")and ($elt/following-sibling::item[3]/a[4]/text()="P+D")) then ( concat($elt/a[2]/text()," ",$elt/following-sibling::item[1]/a[2]/text()," ",$elt/following-sibling::item[2]/a[2]/text()," ", $elt/following-sibling::item[3]/a[2]/text()) ) else ( " " ) where $conc2 != " " return $conc2