Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xpath 需要在XML代码中查找重叠日期_Xpath_Schematron - Fatal编程技术网

Xpath 需要在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" />

我需要帮助查找此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, '-', '') &lt;= 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, '-', '') 
            &lt;=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, '-', '') &lt;= 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, '-', '') &lt;= preceding::StatusApplicationControl/translate(@End, '-', '')  ">The @Start="<value-of select="@Start"/>" and @End="<value-of select="@End"/>" dates are overlaping</report>
        </rule>