NFE-321
The rule sets below word this rule differently; each wording is shown with its rule set.
What the rule checks
As the rule set's publisher wrote it. The rule runs on every element the context matches, and fails where the test is false; the validator reports the line of that element.
Rejeição: NF-e de devolução de mercadoria não possui documento fiscal referenciado.
nfe:infNFe
$fin != '4' or $refs or $det/nfe:DFeReferenciado or $cfops = ('1201', '1202', '1410', '1411', '5921', '6921')
Checked with NF-e 4.00, NF-e 4.00 with authorisation protocol
Rejeição: NF-e de devolução de mercadoria não possui documento fiscal referenciado a nível de item (DFeReferenciado/chaveAcesso, obrigatório a partir de …).
nfe:infNFe
not($fin = '4' and exists($emitted) and $emitted ge $later) or (every $d in $det satisfies $d/nfe:DFeReferenciado/nfe:chaveAcesso)
Checked with NF-e 4.00, NF-e 4.00 with authorisation protocol