CFDI40151

El RFC del receptor es de un RFC registrado en el SAT o un RFC genérico nacional y existe el campo ResidenciaFiscal.

In English ResidenciaFiscal must be left out unless the receiver is a foreigner with the generic RFC XEXX010101000.

error: the document is invalid

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.

Context
/cfdi:Comprobante/cfdi:Receptor
Test
$foreign or not(@ResidenciaFiscal)

Checked with CFDI 4.0