<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>
我正试图找出一种方法来判断&lt; TypeAllocation @Start和@ End&gt;日期在&lt; BlockDates @Start和@End&gt;之外日期。可以有任意数量的&lt; TypeAllocation&gt;元素和&lt;类型&gt;元素。在所有情况下,上述情况都应失败。以下是我的尝试。但是我感觉它离开了,因为它只发现了第一个。非常感谢任何帮助!
<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>
答案 0 :(得分:1)
如果至少有一个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>
答案 1 :(得分:0)
我能够使用以下方法实现此目的。非常感谢Martin的帮助!
<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>