0
我正在嘗試在XSLT中創建類信用總和,但我無法弄清楚在哪裏放置求和語句。使用XSLT對分組的XML工作流程中的數據進行求和
這裏是和發言中,我創建了:
<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>
</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>
</xsl:text><Degreetitle><xsl:apply-templates select="ACPGDEGREE1" /></Degreetitle>
<Certtitle><xsl:apply-templates select="CCD11" /></Certtitle><xsl:text>
</xsl:text>
<DegreeDesc><xsl:apply-templates select="ACPGCOMMENTS1" /></DegreeDesc>
<xsl:text>
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>
</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>
</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>
</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>
最終的輸出將被導入到Adobe 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