首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SchemaTron数据比较

SchemaTron数据比较
EN

Stack Overflow用户
提问于 2016-10-14 16:18:01
回答 2查看 251关注 0票数 1
代码语言:javascript
复制
<ROOTNODE>
   <Blocks>
     <Block>
    <Ref/>
      <BlockDates Start="2015-10-20" End="2015-10-25" />
      <Types>
        <Type TypeCode="SGL">
         <TypeAllocations>
        <TypeAllocation Start="2015-10-26" End="2015-10-27" />
        <TypeAllocation Start="2015-10-26" End="2015-10-25" />
      </TypeAllocations>
       </Type>
         <Type TypeCode="SGL">
         <TypeAllocations>
        <TypeAllocation Start="2015-10-28" End="2015-10-29" />
        <TypeAllocation Start="2015-10-26" End="2015-10-27" />
      </TypeAllocations>
       </Type>
      </Types>
    </Block>

    <Block>
      <Ref/>
      <BlockDates Start="2015-10-26" End="2015-10-30"/>
       <Types>
        <Type TypeCode="SG">
         <TypeAllocations>
        <TypeAllocation Start="2015-10-31" End="2015-11-01" />
        <TypeAllocation Start="2015-10-25" End="2015-10-24" />
      </TypeAllocations>
       </Type>
         <Type TypeCode="SG">
         <TypeAllocations>
        <TypeAllocation Start="2015-10-21" End="2015-10-25" />
        <TypeAllocation Start="2015-10-23" End="2015-11-27" />
      </TypeAllocations>
       </Type>
      </Types>
    </Block>
   </Blocks>
   </ROOTNODE>

我试图找到一种方法来判断日期是否在日期之外。可以有任意数量的元素和元素。上述情况在所有情况下都应失败。下面是我试过的。然而,我觉得它的出路,因为它只找到了第一个。任何帮助都是非常感谢的!

代码语言:javascript
复制
   <sch:pattern name="Testing Start and End dates">
                                                                                <sch:rule context="blk:InvBlock">
                                                                                    <sch:report test="translate(blk:InvBlockDates/@Start, '-', '') &lt;= translate(blk:RoomTypes/blk:RoomType/blk:RoomTypeAllocations/blk:RoomTypeAllocation/@Start, '-', '') or translate(blk:InvBlockDates/@End, '-', '') &lt;= translate(blk:RoomTypes/blk:RoomType/blk:RoomTypeAllocations/blk:RoomTypeAllocation/@End, '-', '')"> Allocation @Start and @End dates can not be outside the Block @Start and @End dates. </sch:report>
                                                                                </sch:rule>
                                                                            </sch:pattern> 
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-10-14 16:47:54

我不确定您是否想报告验证错误,如果至少有一个TypeAllocation与错误的StartEnd,或者您想要检查所有这些。如果您只想检查其中至少一个错误,则可以使用

代码语言:javascript
复制
<sch:pattern>
    <sch:rule context="Block">
        <sch:report test="Types/Type/TypeAllocations/TypeAllocation[
                            translate(@Start, '-', '') > translate(current()/BlockDates/@Start, '-', '')
                            or
                            translate(@End, '-', '') > translate(current()/BlockDates/@End, '-', '')]"> Allocation @Start and @End dates can not be outside the Block @Start and @End dates. </sch:report>
    </sch:rule>
</sch:pattern> 

我认为。如果Schematron的版本不支持使用current()函数,那么在示例的上下文中,我建议您可以使用ancestor::Block而不是current()

代码语言:javascript
复制
<sch:pattern>
    <sch:rule context="Block">
        <sch:report test="Types/Type/TypeAllocations/TypeAllocation[
                            translate(@Start, '-', '') > translate(ancestor::Block/BlockDates/@Start, '-', '')
                            or
                            translate(@End, '-', '') > translate(ancestor::Block/BlockDates/@End, '-', '')]"> Allocation @Start and @End dates can not be outside the Block @Start and @End dates. </sch:report>
    </sch:rule>
</sch:pattern> 
票数 1
EN

Stack Overflow用户

发布于 2016-10-17 16:27:59

我能够使用以下方法完成这项工作。非常感谢你的帮助马丁!

代码语言:javascript
复制
<sch:rule context="Block">
    <sch:report test="Types/Type/TypeAllocations/TypeAllocation[
    translate(@Start, '-', '') &lt; translate(ancestor::Block/BlockDates/@Start, '-', '') ]
    or
    Types/Type/TypeAllocations/TypeAllocation[translate(@End, '-', '') &gt; translate(ancestor::Block/BlockDates/@End, '-', '')] ">
    Allocation @Start and @End dates can not be outside the Block @Start and @End dates.
    </sch:report>
</sch:rule>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40047766

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档