Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.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
使用XSLT2.0比较两个节点集以检测缺少的节点_Xslt - Fatal编程技术网

使用XSLT2.0比较两个节点集以检测缺少的节点

使用XSLT2.0比较两个节点集以检测缺少的节点,xslt,Xslt,我需要用XSLT比较两个变量节点,并检查$Items1中是否有$Items 2中缺少的项: <!-- $Items1 --> <Items> <Item Name="1"></Item> <Item Name="2"></Item> <Item Name="I'm missing"></Item> </Items> <!-- $Items2 --> &

我需要用XSLT比较两个变量节点,并检查$Items1中是否有$Items 2中缺少的项:

<!-- $Items1 -->
<Items>
    <Item Name="1"></Item>
    <Item Name="2"></Item>
    <Item Name="I'm missing"></Item>
</Items>

<!-- $Items2 -->
<Items>
    <Item Name="1"></Item>
    <Item Name="2"></Item>
</Items>

到目前为止,我所做的工作仍在进行,但我需要在发送丢失项目的消息后终止该过程:

  <xsl:template match="/">
    <xsl:for-each select="$Items1/Item/@Name">
        <xsl:choose>
            <xsl:when xpath-default-namespace="" test="not($Items2/@Name = current())">
                <xsl:message terminate="no">
                    <xsl:text>missing items </xsl:text>
                    <xsl:value-of select="current()" />
                </xsl:message>
            </xsl:when>
        </xsl:choose>
    </xsl:for-each>

遗失物品
是否有一种方法可以设置一个标志或某种东西,以便我可以在循环后检查并终止进程,或者将缺少的项写入数组并检查数组是否大于1

<xsl:if test="$flag='true'">
        <xsl:message terminate="yes">
            <xsl:text>Process terminated</xsl:text>
        </xsl:message>
</xsl:if>

进程终止

我建议定义一个键

<xsl:key name="by-name" match="Items/Item" use="@Name"/>

然后定义一个变量

<xsl:variable name="not-matched" select="$Items1/Item[not(key('by-name', @Name, $Items2))]"/>

现在您可以检查


使用
xpath默认名称空间
表明,可能需要将键设置为
,我需要查看上下文和任何名称空间声明,以准确说明您需要什么。

我建议定义一个键

<xsl:key name="by-name" match="Items/Item" use="@Name"/>

然后定义一个变量

<xsl:variable name="not-matched" select="$Items1/Item[not(key('by-name', @Name, $Items2))]"/>

现在您可以检查


使用
xpath默认名称空间
表明,可能需要将键设置为
,我需要查看上下文和任何名称空间声明,以准确说明您需要什么。

我建议定义一个键

<xsl:key name="by-name" match="Items/Item" use="@Name"/>

然后定义一个变量

<xsl:variable name="not-matched" select="$Items1/Item[not(key('by-name', @Name, $Items2))]"/>

现在您可以检查


使用
xpath默认名称空间
表明,可能需要将键设置为
,我需要查看上下文和任何名称空间声明,以准确说明您需要什么。

我建议定义一个键

<xsl:key name="by-name" match="Items/Item" use="@Name"/>

然后定义一个变量

<xsl:variable name="not-matched" select="$Items1/Item[not(key('by-name', @Name, $Items2))]"/>

现在您可以检查


使用
xpath默认名称空间
表明,可能关键需要是
,我需要查看上下文和任何名称空间声明,以准确地告诉您需要什么。

这种方法如何:

<xsl:template match="/">
   <xsl:variable name="missing" select="$Items1/Item/@Name[not(. = $Items2/@Name)]" />
   <xsl:choose>
       <xsl:when test="$missing">
          <xsl:text>missing items&#xA;</xsl:text>
          <xsl:for-each select="$missing">
                <xsl:value-of select="concat(current(), '&#xA;')" />
          </xsl:for-each>
       </xsl:when>
       <xsl:otherwise>
           <!-- Continue normal operation -->
       </xsl:otherwise>
   </xsl:choose>
</xsl:template>

缺失项目
;
或者:

<xsl:template match="/">
   <xsl:variable name="missing" select="$Items1/Item/@Name[not(. = $Items2/@Name)]" />

   <xsl:if test="$missing">
       <xsl:text>missing items&#xA;</xsl:text>
       <xsl:for-each select="$missing">
            <xsl:value-of select="concat(current(), '&#xA;')" />
       </xsl:for-each>
       <xsl:message terminate="yes">
          <xsl:text>Process terminated</xsl:text>
       </xsl:message>
   </xsl:if>

   <!-- Continue normal operation -->

</xsl:template>

缺失项目
;
进程终止

这种方法怎么样:

<xsl:template match="/">
   <xsl:variable name="missing" select="$Items1/Item/@Name[not(. = $Items2/@Name)]" />
   <xsl:choose>
       <xsl:when test="$missing">
          <xsl:text>missing items&#xA;</xsl:text>
          <xsl:for-each select="$missing">
                <xsl:value-of select="concat(current(), '&#xA;')" />
          </xsl:for-each>
       </xsl:when>
       <xsl:otherwise>
           <!-- Continue normal operation -->
       </xsl:otherwise>
   </xsl:choose>
</xsl:template>

缺失项目
;
或者:

<xsl:template match="/">
   <xsl:variable name="missing" select="$Items1/Item/@Name[not(. = $Items2/@Name)]" />

   <xsl:if test="$missing">
       <xsl:text>missing items&#xA;</xsl:text>
       <xsl:for-each select="$missing">
            <xsl:value-of select="concat(current(), '&#xA;')" />
       </xsl:for-each>
       <xsl:message terminate="yes">
          <xsl:text>Process terminated</xsl:text>
       </xsl:message>
   </xsl:if>

   <!-- Continue normal operation -->

</xsl:template>

缺失项目
;
进程终止

这种方法怎么样:

<xsl:template match="/">
   <xsl:variable name="missing" select="$Items1/Item/@Name[not(. = $Items2/@Name)]" />
   <xsl:choose>
       <xsl:when test="$missing">
          <xsl:text>missing items&#xA;</xsl:text>
          <xsl:for-each select="$missing">
                <xsl:value-of select="concat(current(), '&#xA;')" />
          </xsl:for-each>
       </xsl:when>
       <xsl:otherwise>
           <!-- Continue normal operation -->
       </xsl:otherwise>
   </xsl:choose>
</xsl:template>

缺失项目
;
或者:

<xsl:template match="/">
   <xsl:variable name="missing" select="$Items1/Item/@Name[not(. = $Items2/@Name)]" />

   <xsl:if test="$missing">
       <xsl:text>missing items&#xA;</xsl:text>
       <xsl:for-each select="$missing">
            <xsl:value-of select="concat(current(), '&#xA;')" />
       </xsl:for-each>
       <xsl:message terminate="yes">
          <xsl:text>Process terminated</xsl:text>
       </xsl:message>
   </xsl:if>

   <!-- Continue normal operation -->

</xsl:template>

缺失项目
;
进程终止

这种方法怎么样:

<xsl:template match="/">
   <xsl:variable name="missing" select="$Items1/Item/@Name[not(. = $Items2/@Name)]" />
   <xsl:choose>
       <xsl:when test="$missing">
          <xsl:text>missing items&#xA;</xsl:text>
          <xsl:for-each select="$missing">
                <xsl:value-of select="concat(current(), '&#xA;')" />
          </xsl:for-each>
       </xsl:when>
       <xsl:otherwise>
           <!-- Continue normal operation -->
       </xsl:otherwise>
   </xsl:choose>
</xsl:template>

缺失项目
;
或者:

<xsl:template match="/">
   <xsl:variable name="missing" select="$Items1/Item/@Name[not(. = $Items2/@Name)]" />

   <xsl:if test="$missing">
       <xsl:text>missing items&#xA;</xsl:text>
       <xsl:for-each select="$missing">
            <xsl:value-of select="concat(current(), '&#xA;')" />
       </xsl:for-each>
       <xsl:message terminate="yes">
          <xsl:text>Process terminated</xsl:text>
       </xsl:message>
   </xsl:if>

   <!-- Continue normal operation -->

</xsl:template>

缺失项目
;
进程终止