Checking Assertions

The code for checking input data against assertions defined in the schema is very straightforward. Here is the actual logic (no simplifications this time):

<xsl:function name="scm:check-assertions" as="map(*)" saxon:as="tuple(error:
            element(vr:error)*)">
    <xsl:param name="type" as="element(scm:complexType)"/>
    <xsl:param name="node" as="element()"/>
    <xsl:variable name="copy-sans-comments" as="element()">
        <xsl:apply-templates select="$node" mode="copy-sans-comments"/>
    </xsl:variable>
    <xsl:variable name="failures" as="element(vr:error)*">
        <xsl:for-each select="$type/scm:assertion">
            <xsl:try>
                <xsl:variable name="assertion-result" as="item()*">
                    <xsl:evaluate xpath="@test" 
                        context-item="$copy-sans-comments"  
                        namespace-context="scm:make-namespace-context(.)"
                        base-uri="{base-uri($scm)}">
                        <xsl:with-param name="value" select="$copy-sans-comments"/>
                    </xsl:evaluate>
                </xsl:variable>
                <xsl:if test="not($assertion-result)">
                    <xsl:sequence select="scm:error($node, ' must satisfy assertion '
                    || @test)"/>
                </xsl:if>
                <xsl:catch errors="*">
                    <xsl:sequence select="scm:error($node, ' must satisfy assertion ' 
                    || @test || '.
                            Evaluation of the assertion failed with a dynamic error: '
                            || $err:description)"/>
                </xsl:catch>
            </xsl:try>
        </xsl:for-each>
    </xsl:variable>
    <xsl:sequence select="map{'errors': $failures}"/>
</xsl:function>

Notes relating to this code: