【问题标题】:SchemaTron check preceding attributesSchemaTron 检查前面的属性
【发布时间】:2016-10-11 20:01:58
【问题描述】:
  <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>

【问题讨论】:

  • 马丁,这很完美。 -谢谢!

标签: xslt xpath schematron


【解决方案1】:

我会使用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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-25
    • 2014-02-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多