0

我试图在我的 XSLT 中创建一个班级学分总和,但我不知道在哪里放置 sum 语句。

这是我创建的 sum 语句:

   <credit-sum><xsl:value-of select='format-number(sum(CRSMINCRED1),"##")'/></credit-sum>

数据分为三组:

1. by Area of Study
2. By Degree
3. By Requirement or Elective status 

我只想总结“必修”课程的学分。但是,当我将 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>

最终输出将被导入 Adob​​e InDesign 并应如下所示: ...

 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
4

1 回答 1

0

似乎CourseCroup模板是进行此更改的地方:

  <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>

然后您将只修改第一个call-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>
于 2013-02-14T06:46:16.813 回答