Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.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
使用XSLT对分组XML工作流中的数据求和_Xml_Xslt - Fatal编程技术网

使用XSLT对分组XML工作流中的数据求和

使用XSLT对分组XML工作流中的数据求和,xml,xslt,Xml,Xslt,我试图在XSLT中创建一个类积分的总和,但我不知道将sum语句放在哪里 以下是我创建的sum语句: <credit-sum><xsl:value-of select='format-number(sum(CRSMINCRED1),"##")'/></credit-sum> 我只想计算“必修”课程的学分。但当我把sum语句放进去时,它只是单独显示每个类的总数,而不是类组 以下是XSLT: <?xml version="1.0"?><!-

我试图在XSLT中创建一个类积分的总和,但我不知道将sum语句放在哪里

以下是我创建的sum语句:

   <credit-sum><xsl:value-of select='format-number(sum(CRSMINCRED1),"##")'/></credit-sum>
我只想计算“必修”课程的学分。但当我把sum语句放进去时,它只是单独显示每个类的总数,而不是类组

以下是XSLT:

<?xml version="1.0"?><!-- DWXMLSource="STX049-2-8-13-parsed.xml" -->
<!DOCTYPE xsl:stylesheet>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="no"/>
<xsl:variable name="allSections" select="/CrystalReport/Group/Group/Group/Details/Section" />

<xsl:key name="kArea" match="Section" use="ACPGAREAOFSTUDY1"/>
<xsl:key name="kDegree" match="Section" use="concat(ACPGAREAOFSTUDY1, '+', ACPGDEGREE1)" />
<xsl:key name="kDepartment" match="Section" use="concat(ACPGAREAOFSTUDY1, '+', ACPGDEGREE1, '+', ICCB1)" />

<xsl:variable name="degreeFirsts" select="$allSections[generate-id() = generate-id(key('kDegree', concat(ACPGAREAOFSTUDY1, '+', ACPGDEGREE1))[1])]" />
<xsl:variable name="deptFirsts" select="$allSections[generate-id() = generate-id(key('kDepartment', concat(ACPGAREAOFSTUDY1, '+', ACPGDEGREE1, '+', ICCB1))[1])]" />


<xsl:template match="/">
<CrystalReport>
<Degrees>
<xsl:apply-templates select="$allSections[generate-id() = generate-id(key('kArea', ACPGAREAOFSTUDY1)[1])]" mode="group"/>
</Degrees>
</CrystalReport>
</xsl:template>

<xsl:template match="Section" mode="group">
<xsl:variable name="area" select="ACPGAREAOFSTUDY1" />
<xsl:text>&#xA;</xsl:text>
<areaofstudy><xsl:value-of select="$area"/></areaofstudy>
<xsl:apply-templates select="$degreeFirsts[ACPGAREAOFSTUDY1 = $area]" mode="degree"/>
</xsl:template>

<xsl:template match="Section" mode="degree">
<xsl:variable name="area" select="ACPGAREAOFSTUDY1" />
<xsl:variable name="degree" select="ACPGDEGREE1" />
<Degree>
<xsl:apply-templates select="$deptFirsts[ACPGAREAOFSTUDY1 = $area and ACPGDEGREE1 = $degree]" mode="department">
<xsl:sort select="ACADPROGRAMSID1" />
</xsl:apply-templates>
</Degree>
</xsl:template>

<xsl:template match="Section" mode="department">
<department><xsl:text>&#xA;</xsl:text><Degreetitle><xsl:apply-templates select="ACPGDEGREE1" /></Degreetitle>
<Certtitle><xsl:apply-templates select="CCD11" /></Certtitle><xsl:text>&#xA;</xsl:text>
<DegreeDesc><xsl:apply-templates select="ACPGCOMMENTS1" /></DegreeDesc>
<xsl:text>&#xA;ICCB Code </xsl:text><ICCBcode><xsl:apply-templates select="ICCB1" /></ICCBcode>
<xsl:text> | Field of Study Code: </xsl:text><ProgramID><xsl:apply-templates select="ACADPROGRAMSID1" /></ProgramID>

<xsl:variable name="courses" select="key('kDepartment', concat(ACPGAREAOFSTUDY1, '+', ACPGDEGREE1, '+', ICCB1))" />

<xsl:call-template name="CourseGroup">
<xsl:with-param name="courses" select="$courses[FlagElectives1 = 'N']" />
<xsl:with-param name="title" select="'Program Requirements'" />
</xsl:call-template>

<xsl:call-template name="CourseGroup">
<xsl:with-param name="courses" select="$courses[FlagElectives1 = 'Y']" />
<xsl:with-param name="title" select="'Program Electives'" />
</xsl:call-template>
<xsl:apply-templates select="ACPGHOMELANGNOTREQDRSN1" />
</department>
</xsl:template>

<xsl:template name="CourseGroup">
<xsl:param name="courses" />
<xsl:param name="title" />

<xsl:if test="$courses"><xsl:text>&#xA;</xsl:text>
<req-electitle><xsl:value-of select="$title" /></req-electitle>
<xsl:apply-templates select="$courses">
<xsl:sort select="FlagElectives1" order="ascending" />
<xsl:sort select="CRSSUBJECT1" />
<xsl:sort select="CRSNO1" />
</xsl:apply-templates>
</xsl:if>
</xsl:template>

<xsl:template match="Section">
<xsl:text>&#xA;</xsl:text>
<Details>
<class><deptname><xsl:apply-templates select="CRSSUBJECT1" /></deptname><xsl:text>  </xsl:text>
<courseno><xsl:apply-templates select="CRSNO1" /></courseno><xsl:text>  </xsl:text>
<classname><xsl:apply-templates select="CRSTITLE1" /></classname><xsl:text> </xsl:text>
<classcredit><xsl:apply-templates select="CRSMINCRED1" /></classcredit>
<xsl:apply-templates select="CRSMAXCRED1" />
</class>
</Details>
</xsl:template>

<xsl:template match="ACPGHOMELANGNOTREQDRSN1[string-length() != 0]">
<xsl:text>&#xA;</xsl:text><totalcredits><xsl:value-of select="normalize-space(.)" /></totalcredits>
</xsl:template>

<xsl:template match="CRSMAXCRED1[string-length() != 0]">
<xsl:text> to </xsl:text><maxcredits><xsl:value-of select="normalize-space(.)" /></maxcredits>
</xsl:template>

<xsl:template match="ACPGDEGREE1/text()">
<xsl:value-of select="concat(., ' DEGREE')"/>
</xsl:template>

<xsl:template match="CCD11/text()">
<xsl:value-of select="('CERTIFICATE')" />
</xsl:template>

</xsl:stylesheet>

似乎
课程组
模板就是进行此更改的地方:

  <xsl:template name="CourseGroup">
    <xsl:param name="courses" />
    <xsl:param name="title" />
    <xsl:param name="requiredCourses" select="false()" />

    <xsl:if test="$courses">
      <xsl:text>&#xA;</xsl:text>
      <req-electitle>
        <xsl:value-of select="$title" />
      </req-electitle>
      <xsl:apply-templates select="$courses">
        <xsl:sort select="FlagElectives1" order="ascending" />
        <xsl:sort select="CRSSUBJECT1" />
        <xsl:sort select="CRSNO1" />
      </xsl:apply-templates>
      <xsl:if test="$requiredCourses">
        <credit-sum>
          <xsl:value-of select='format-number(sum($courses/CRSMINCRED1),"##")'/>
        </credit-sum>
      </xsl:if>
    </xsl:if>
  </xsl:template>
 ICCB Code 4903 | Field of Study Code: AIRC.CER.ENERG
 Program Requirements
 AIRC   2232    Energy Audits/Economics                     2
 AIRC   2240    Load Calculations and Duct Design           5
 AIRC   2260    Heating and Air Conditioning Contracting    3
 Total Credits                                             10
  <xsl:template name="CourseGroup">
    <xsl:param name="courses" />
    <xsl:param name="title" />
    <xsl:param name="requiredCourses" select="false()" />

    <xsl:if test="$courses">
      <xsl:text>&#xA;</xsl:text>
      <req-electitle>
        <xsl:value-of select="$title" />
      </req-electitle>
      <xsl:apply-templates select="$courses">
        <xsl:sort select="FlagElectives1" order="ascending" />
        <xsl:sort select="CRSSUBJECT1" />
        <xsl:sort select="CRSNO1" />
      </xsl:apply-templates>
      <xsl:if test="$requiredCourses">
        <credit-sum>
          <xsl:value-of select='format-number(sum($courses/CRSMINCRED1),"##")'/>
        </credit-sum>
      </xsl:if>
    </xsl:if>
  </xsl:template>
  <xsl:call-template name="CourseGroup">
    <xsl:with-param name="courses" select="$courses[FlagElectives1 = 'N']" />
    <xsl:with-param name="title" select="'Program Requirements'" />
    <xsl:with-param name="requiredCourses" select="true()" />
  </xsl:call-template>