I am attempting to add a custom function to my schematron rule stylesheet to aid in looking up values in code tables. I continue to receive an error message: 'XPST0017 XPath syntax at char 0 on line 545 near (...ookupExpression('SEX'): Cannot find a matching 1-argument function named (functions:1.0)BuildLookupExpression())'

At the top of the file, I have the following declarations:

<?xml version="1.0" encoding="UTF-8"?> 
<schema xmlns="http://purl.oclc.org/dsdl/schematron"

    <sch:ns uri="functions:1.0" prefix="local-fn" />

and the function declaration as:

<!-- *********************************** Functions ***********************  --> 
<!-- special variables for lookup table --> 
<xsl:key name="Code-Lookup" match="CodeTable" use="Code"/> 
<xsl:variable name="codeTables" select="document('LookupCodes.xml')/CodeTable"/> 
<!-- function to return an expression to be evaluated in the rule containing the codes from the given code table --> 
<xsl:function name="local-fn:BuildLookupExpression" as="xs:string"> 
    <xsl:param name="TableName" as="xs:string"/> 
    <xsl:for-each select="key('Code-Lookup', $TableName)/Code"> 
        <xsl:value-of select="."/> 
        <xsl:if test="position() != last()"> 
         <xsl:if test="position() = last()"> 

in the body, I use the rule:

    <sch:pattern id="SEXValue"> 
        <sch:title>Person Sex</sch:title> 
        <sch:p class="description">
            This field is used to report the gender of the subject.
            See SEX Table: [F, G, M, N, X, Y, Z]

        <let name="SEXExpression" value="local-fn:BuildLookupExpression('SEX')"/> 
        <sch:rule context="nc:PersonSexCode"> 
            <let name="SEXString" value="string(.)"/> 
            <sch:assert test="matches($SEXString, $SEXExpression)"> 
                <sch:value-of select="name(.)" /> must be in the set of: [F, G, M, N, X, Y, Z] 

What am I missing?