2016-10-14 2 views
1
<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> 

Я пытаюсь найти способ, чтобы сказать, если < TypeAllocation @start и @end > даты вне < BlockDates @start и @end > даты. Может быть любое количество < ТипAlocation > элементов и < Тип > элементов. Вышеизложенное не должно срабатывать во всех случаях. Ниже я попытался. Однако я чувствую, что это отходит, поскольку он только находит первый. Любая помощь очень ценится!Schematron Дата Сравнение

<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> 
+0

Привет, Мартин, Да, мне нужно проверить все начальные и конечные даты распределения с-в блоке. Я забыл упомянуть, что я использую Schematron 1.5 с этим. Таким образом, функция current() не работает. – user1128792

ответ

0

Я был в состоянии получить эту работу, используя следующее. Большое вам спасибо за помощь Мартин!

<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> 
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>