[XProc Challenge] Implement this rule: All person's social security number must be unique

Hi Folks,

Consider this business rule:


   All person's social security number 
   must be unique.


How would you implement the rule, using only native XProc steps? (i.e. don't escape to XSLT)

Below is an implementation I created. Can you come up with a better implementation? 

/Roger


*****************************************************
          check-SSNs.xpl
*****************************************************
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
                xmlns:c="http://www.w3.org/ns/xproc-step">
    
    <p:input port="SSNs">
        <p:document href="SSNs.xml" />
    </p:input>
    <p:output port="result" />

    <p:filter select="/*[count(distinct-values(//@ssn)) eq count(//@ssn)]" />

    <p:count />

    <p:choose>
        <p:when test="number(c:result) gt 0">
            <p:identity>
                <p:input port="source">
                    <p:inline><unique-SSNs>true</unique-SSNs></p:inline>
                </p:input>
            </p:identity>
        </p:when>
        <p:otherwise>
            <p:identity>
                <p:input port="source">
                    <p:inline><unique-SSNs>false</unique-SSNs></p:inline>
                </p:input>
            </p:identity>
        </p:otherwise>
    </p:choose>
    
</p:declare-step>


*****************************************************
          SSNs.xpl
*****************************************************
<?xml version="1.0"?>
<SSNs>
    <Person ssn="365-78-2145" />
    <Person ssn="430-43-4530" />
    <Person ssn="201-59-3021" />
    <Person ssn="590-10-0902" />
    <Person ssn="430-32-4329" />
</SSNs>

Received on Sunday, 5 July 2009 22:21:37 UTC