SchemaTron 检查前面的属性

SchemaTron check preceding attributes

  <ROOTNODE>
   <Blocks>
     <Block>
    <Ref/>
      <BlockDates Start="2015-10-20" End="2015-10-20" />
      <Types>
        <Type TypeCode="SGL" />
      </Types>
    </Block>

    <Block>
      <Ref/>
      <BlockDates Start="2015-10-19" End="2015-10-18"/>
      <Types>
        <Type TypeCode="SGL" />
       </Types>
    </Block>
   </Blocks>
   </ROOTNODE>

如果@Start 日期小于前面的@End 日期,我需要报错。但前提是@TypeCode 与前面的@TypeCode 相同。以上应该会产生错误。以下是我尝试过的。感谢您的帮助!

   <sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron">
                <sch:pattern>
                    <sch:rule context="BlockDates|Type">
                            <sch:report test="translate(@Start, '-', '') &lt;= translate(preceding::*/@End, '-', '') and @TypeCode = preceding::*/@TypeCode"> Error start date is before end date and type codes match.     </sch:report>                                                               
    </sch:rule>                                    </sch:pattern>                                                              
    </sch:schema>

我会使用 Block 元素作为上下文:

<sch:pattern>
    <sch:rule context="Block[Types/Type/@TypeCode = preceding-sibling::Block[1]/Types/Type/@TypeCode]">
        <sch:assert test="translate(BlockDates/@Start, '-', '') &lt; translate(preceding-sibling::Block[1]/@End, '-', '')"></sch:assert>
    </sch:rule>
</sch:pattern>