<?xml version="1.0" encoding="UTF-8"?>
<sch:pattern id="deprecatedWarning" abstract="true" xmlns:sch="http://purl.oclc.org/dsdl/schematron">
    <sch:p id="ruleText">$rule</sch:p>
    <sch:p id="codeDesc">$code</sch:p>
    
    <!-- Depends on params:
         - $rule (rule text)
         - $code (english breakdown of the code)
         - $context (context for the rule)
         - $attrib (name of the attribute being tested)
         - $depValues (depreceated values to test for)
         - $depDates (related deprecation dates for the depValues)
    -->
    <sch:rule id="deprecateWarn" context="$context">
        <sch:let name="attrName" value="'$attrib'"/>
        <sch:let name="curDate" value="translate($ISM_RESOURCE_ELEMENT/@ism:createDate,'-','')"/>
        <sch:let name="values" value="
            for $each in $depValues return 
                if(index-of(tokenize(./@ism:$attrib,' '), $each)>0) 
                    then $each 
                    else null"/>
        <sch:let name="reportWarn" value="
            for $each in $values return
            if($curDate &lt; translate(subsequence($depDates,index-of($depValues,$each),1),'-',''))
                    then concat('[',string($each),'] has been deprecated and is not authorized for used after ',
                        string(subsequence($depDates,index-of($depValues,$each),1)))
                    else null
            "/>
        
        <sch:assert 
            test="count($reportWarn)=0"
            flag="warning">
            [ISM-ID-<sch:value-of select="'$ismID'"/>][Warning] For attribute <sch:value-of select="$attrName"/>, value(s) <sch:value-of select="$reportWarn"/>
        </sch:assert>
        
    </sch:rule>
</sch:pattern>