SchemaTron 日期比较
SchemaTron Date Comparison
<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>
我正在尝试找到一种方法来判断 日期是否在 日期之外。可以有任意数量的 元素和 元素。以上应该在所有情况下都失败。以下是我尝试过的。但是我觉得它的路很远,因为它只找到第一个。非常感谢任何帮助!
<sch:pattern name="Testing Start and End dates">
<sch:rule context="blk:InvBlock">
<sch:report test="translate(blk:InvBlockDates/@Start, '-', '') <= translate(blk:RoomTypes/blk:RoomType/blk:RoomTypeAllocations/blk:RoomTypeAllocation/@Start, '-', '') or translate(blk:InvBlockDates/@End, '-', '') <= 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>
如果至少有一个 TypeAllocation
错误 Start
或 End
或如果你想检查所有,我不确定你是否要报告验证错误他们。如果你只想检查其中至少有一个是错误的,那么你可以使用
<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()
:
<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>
我能够使用以下方法使它正常工作。非常感谢您的帮助,马丁!
<sch:rule context="Block">
<sch:report test="Types/Type/TypeAllocations/TypeAllocation[
translate(@Start, '-', '') < translate(ancestor::Block/BlockDates/@Start, '-', '') ]
or
Types/Type/TypeAllocations/TypeAllocation[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>
<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>
我正在尝试找到一种方法来判断
<sch:pattern name="Testing Start and End dates">
<sch:rule context="blk:InvBlock">
<sch:report test="translate(blk:InvBlockDates/@Start, '-', '') <= translate(blk:RoomTypes/blk:RoomType/blk:RoomTypeAllocations/blk:RoomTypeAllocation/@Start, '-', '') or translate(blk:InvBlockDates/@End, '-', '') <= 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>
如果至少有一个 TypeAllocation
错误 Start
或 End
或如果你想检查所有,我不确定你是否要报告验证错误他们。如果你只想检查其中至少有一个是错误的,那么你可以使用
<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()
:
<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>
我能够使用以下方法使它正常工作。非常感谢您的帮助,马丁!
<sch:rule context="Block">
<sch:report test="Types/Type/TypeAllocations/TypeAllocation[
translate(@Start, '-', '') < translate(ancestor::Block/BlockDates/@Start, '-', '') ]
or
Types/Type/TypeAllocations/TypeAllocation[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>