Xpath 需要在XML代码中查找重叠日期
我需要帮助查找此XML代码中的重叠日期。我需要确保结束日期不小于或等于继续的开始日期Xpath 需要在XML代码中查找重叠日期,xpath,schematron,Xpath,Schematron,我需要帮助查找此XML代码中的重叠日期。我需要确保结束日期不小于或等于继续的开始日期 <Inventory> <StatusApplicationControl Start="2019-07-18" End="2019-07-18" InvTypeCode="STDX" /> <InvCounts> <InvCount CountType="2" Count="9" />
<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=”“和@End=”“日期重叠
我希望这封信能被打印出来-
Start=“2019-07-18”小于或等于End=“2019-07-18”日期
非常感谢您的帮助 看来这些评论对你没有帮助 规则应当是:
<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规则。问题正在将前面的:传递给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>
@Start=”“和@End=”“日期重叠
不清楚您的实际输出是什么。除此之外,您的邮件似乎使用了同一上下文中的开始
和结束
属性。感谢Alejandro,我更改了上述代码,现在它可以工作了,但我无法获取开始和结束日期的值。如果您正在比较StatusApplicationControl/@Start
和previous::Inventory/previous::StatusApplicationControl/@End
,为什么您的消息使用@Start
和@End
?因为这些值只能来自上下文。因此,要获取这些值,上下文必须是context=“Inventory/StatusApplicationControl”
,但您需要“other”@End
属性……感谢Alejandro,但我使用该规则时会遇到Schematron异常。传递任何其他@End
都会导致异常。当从选择中删除previous::Inventory[1]/StatusApplicationControl
时,它可以工作。嗨,Alejandro,上面的规则只适用于2个Inventory
块如何使它与更多块一起工作?谢谢谢谢Alejandro,我想这是Schematron引擎的不同之处。我用的是这个,你的规则不适用。我以为所有的实现都是一样的,但我想不是。再次感谢你的帮助!Schematron引擎使用XPath 2.0。-此表达式转换(previous::Inventory[1]/StatusApplicationControl/@End,'-','')
报告错误的唯一方式是因为每个Inventory
都有许多状态ApplicationControl
,而您的输入示例没有显示这些内容。嗨,Alejandro,是的,我使用的是XPath 2.0,但正如我的示例所示,对于每个清单,我只有一个StatusApplicationControl
,因此不确定这是否是因为我使用了.NET Schematon。请注意,此表达式previous::StatusApplicationControl/translate(@End',-','')
不是XPath 1.0,在XPath 2.0中,它将导致与前面所有(任何级别)@End
属性的存在性比较。是的,我需要它来比较前面所有的值,我永远不知道会有多少+1指出这是XPath版本的差异!
<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.
<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>