Q: Can an external custom Python function be called using Saxon and XSD 1.1 assertions? An answer to a question here regarding whether custom Java methods can be called to validate XML data says that it can be done using Saxon processor and XSD 1.1 assertions.
Can Saxon be used to call a custom Python function to validate XML data when using the Python saxonc module?
Presumably, it would be something akin to:
<xs:simpleType name="PostCode" base="xs:string">
    <xs:assert test="ext:is_valid_post_code($value)" xmlns:ext="python:ValidationModule"/>
</xs:simpleType>

If yes, can someone provide an example?

A: This isn't something that's currently supported "out of the box". It's possible you can find a way to make it work by calling via C/C++; but I doubt that use of extension functions in XSD assertions has been tested in SaxonC, so you're on the bleeding edge here if you want to try it.

A: Use of vendor-specific extensions undermines the benefits of standards and interoperability1.  Consider keeping your XSD validation pure and adding a second phase for any needed Python-based constraint checking.  This is also often easier than wrestling with the idiosyncrasies of extension mechanisms.
1  I'm not saying that extensions have no value or that I don't appreciate vendor effort to provide them — just to offer an alternative and suggest that extension use should be limited to last resort or areas where interoperability isn't important.
