2016-04-27 30 views
-1

我想在循环中声明一个外部变量。但它给我的错误 我的XSLT是 在其范围外使用全局变量

   <xsl:for-each select="document($kush_xml)"> 


         <xsl:variable name="total_error" select="sum(vfiler/@error)"/> 
         <xsl:variable name="total_warning" select="sum(vfiler/@warning)"/> 
        <xsl:variable name="err_cnt"> 
          <xsl:value-of select="count(document($precheck_cft_xml)/ 
          kush/sevenmtt_cft/jobs/precheck_job/result_entries/ 
          resultEntry[result/aptType='BLOCKING_ERROR' and 
          not(contains($filter_cft_codes,result/code)) and 
          result/aptType!='NEW_STEP' and 
          (result/affectedCommonResources/controllerName=$controller or 
          (not(result/affectedCommonResources/controllerName) and 
          (ancestor::precheck_job/@controller_a=$hostname or ancestor::precheck_job/@controller_b=$hostname)))])"/> 

        </xsl:variable> 

        <xsl:variable name="warn_cnt"> 
         <xsl:value-of select="count(document($precheck_cft_xml)/ 
         netapp/sevenmtt_cft/precheck_jobs/precheck_job/result_entries/ 
         resultEntry[result/aptType='SERIOUS_WARNING' and 
         not(contains($filter_cft_codes,result/code)) and 
         result/aptType!='NEW_STEP' and 
         (result/affectedCommonResources/controllerName=$controller or 
         (not(result/affectedCommonResources/controllerName) and 
         (ancestor::precheck_job/@controller_a=$hostname or ancestor::precheck_job/@controller_b=$hostname)))])"/> 
        </xsl:variable> 

我要计算表条目加入total_error and err_cnttotal_warning and warn_cnt

什么我的XML是

<chapter id="4.2.1" heading=" Feasibility">   

     <tbl> 
      <columns> 
       <c name="Controller"/> 
       <c name="Prechecks " align="center"/> 
       <c name="Prechecks Review" align="center"/> 
      </columns> 
     </tbl> 
    </chapter> 

现在该怎么办我想要做的是warn_cnterr_cnt<for-each>循环之外使用。因为我必须根据这些值计算表中的值。不知何故,我无法在标签中创建表格,因为它创建了多个表格。所以我必须在循环外写我的表代码。 我试过的是在变量内使用<for:each>循环,但它没有帮助。 好心帮我

是我的尝试是

<xsl:variable name="warn_cnt"> 
          <xsl:for-each select="document($precheck_xml)/kush/sevenmtt/controller"> 
           <xsl:value-of select="count(document($precheck_cft_xml)/ 
           netapp/sevenmtt_cft/precheck_jobs/precheck_job/result_entries/ 
           resultEntry[result/aptType='SERIOUS_WARNING' and 
           not(contains($filter_cft_codes,result/code)) and 
           result/aptType!='NEW_STEP' and 
           (result/affectedCommonResources/controllerName=$controller or 
           (not(result/affectedCommonResources/controllerName) and 
           (ancestor::precheck_job/@controller_a=$hostname or ancestor::precheck_job/@controller_b=$hostname)))])"/> 
          </xsl:for-each> 
         </xsl:variable> 

<xsl:variable name="err_cnt"> 
          <xsl:for-each select="document($precheck_xml)/netapp/sevenmtt/controller"> 
           <xsl:value-of select="count(document($precheck_cft_xml)/ 
           kush/sevenmtt_cft/precheck_jobs/precheck_job/result_entries/ 
           resultEntry[result/aptType='BLOCKING_ERROR' and 
           not(contains($filter_cft_codes,result/code)) and 
           result/aptType!='NEW_STEP' and 
           (result/affectedCommonResources/controllerName=$controller or 
           (not(result/affectedCommonResources/controllerName) and 
           (ancestor::precheck_job/@controller_a=$hostname or ancestor::precheck_job/@controller_b=$hostname)))])"/> 
          </xsl:for-each> 
         </xsl:variable> 

,但是这是不工作的。

+0

请不要发表相同的问题两次 - 而是花时间和精力澄清你想要的东西。 –

回答

0

没有任何输入和输出它有点难以实现目标是什么。

现在我想要的是让warn_cnt和err_cnt在循环外使用。

但我认为不需要循环。

<xsl:variable name="kush_doc" select="document($kush_xml)" /> 
<xsl:variable name="total_error" select="sum($kush_doc/vfiler/@error)"/> 
<xsl:variable name="total_warning" select="sum($kush_doc/vfiler/@warning)"/>