我需要帮助来查找此XML代码中的重叠日期。我需要确保结束日期不小于或等于开始的开始日期。
<Inventory>
<StatusApplicationControl Start="2019-07-18" End="2019-07-18" InvTypeCode="STDX" />
<InvCounts>
<InvCount CountType="2" Count="9" />
</InvCounts>
</Inventory>
<Inventory>
<StatusApplicationControl Start="2019-07-18" End="2019-07-19" InvTypeCode="STDX" />
<InvCounts>
<InvCount CountType="2" Count="8" />
</InvCounts>
</Inventory>
我尝试了以下代码。
<rule context="Inventory">
<report test="translate(StatusApplicationControl/@Start, '-', '') <= translate(preceding::Inventory/preceding::StatusApplicationControl/@End, '-', '')">The @Start="<value-of select="@Start"/>" and @End="<value-of select="@End"/>" dates are overlaping</report>
</rule>
我希望此消息会被打印- Start =“ 2019-07-18”小于或等于End =“ 2019-07-18”日期
非常感谢您的帮助!
答案 0 :(得分:1)
评论似乎没有帮助您。
规则应为:
<rule context="Inventory">
<report
test="translate(StatusApplicationControl/@Start, '-', '')
<=translate(preceding::Inventory[1]/StatusApplicationControl/@End,'-','')"
>The @Start="<value-of select="@Start"/>" and @End="<value-of
select="preceding::Inventory[1]/StatusApplicationControl/@End"
/>" dates are overlaping</report>
</rule>
编辑
此Schematron
<schema xmlns="http://purl.oclc.org/dsdl/schematron">
<pattern>
<title>Test dates</title>
<rule context="Inventory">
<assert
test="translate(StatusApplicationControl/@Start, '-', '')
> translate(preceding::Inventory[1]/StatusApplicationControl/@End,'-','')"
>The @Start="<value-of
select="StatusApplicationControl/@Start"
/>" and @End="<value-of
select="preceding::Inventory[1]/StatusApplicationControl/@End"
/>" dates are overlaping</assert>
</rule>
</pattern>
</schema>
使用此输入:
<root>
<Inventory>
<StatusApplicationControl Start="2019-07-18" End="2019-07-18" InvTypeCode="STDX" />
<InvCounts>
<InvCount CountType="2" Count="9" />
</InvCounts>
</Inventory>
<Inventory>
<StatusApplicationControl Start="2019-07-18" End="2019-07-19" InvTypeCode="STDX" />
<InvCounts>
<InvCount CountType="2" Count="8" />
</InvCounts>
</Inventory>
</root>
输出:
Pattern 'Test dates' Failed : The @Start="2019-07-18" and @End="2019-07-18" dates are overlaping.
签入https://www.liquid-technologies.com/online-schematron-validator
答案 1 :(得分:0)
这是对我有用的SchemaTron规则。问题是将preceding::
传递给了translate()函数。这样做时,我得到了SchemaTron异常。
<rule context="Inventory/StatusApplicationControl">
<report test="translate(@Start, '-', '') <= preceding::StatusApplicationControl/translate(@End, '-', '') ">The @Start="<value-of select="@Start"/>" and @End="<value-of select="@End"/>" dates are overlaping</report>
</rule>