My XSLT creates three levels of grouping for this college catalog. I need to add one more level to identify optional classes and group them together.
The first level groups on <ACPGAREAOFSTUDY1>
level 2 groups on <ACPGDEGREE1>
and the third level groups on <ICCB1>
The fourth level is based on four elements: <COURSEORAND1>
<GROUPORAND1>
<ACADREQMTBLOCKSID1>
and <GROUPLABEL1>
Here's the logic for the final groupings
When COURSEORAND1 says "OR" GROUPORAND1 is empty. -This means that there are two or more courses to choose from and it will output “OR”
When COURSEORAND1 says "OR" GROUPORAND1 says "AND". -This means that it will output ‘OR’ for the 2 courses in the group. It also means that it would output ‘AND’ for the groups.
The courses can be grouped by element ACADREQMTBLOCKSID1 and those groups can be grouped by GROUPLABEL1.
Here is the current XSLT:
<?xml version="1.0"?>
<!-- DWXMLSource="STX049-2-21-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:with-param name="requiredCourses" select="true()" />
</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:param name="requiredCourses" select="false()" />
<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 test="$requiredCourses">
<xsl:text>
</xsl:text>
<credit-sum>
<xsl:value-of select='format-number(sum($courses/CRSMINCRED1),"##")'/>
</credit-sum>
</xsl:if>
</xsl:if>
</xsl:template>
<xsl:template match="Section">
<xsl:text>
</xsl:text>
<Details>
<xsl:apply-templates select="COURSEORAND1" />
<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="COURSEORAND1[string-length() != 0]">
<courseorand1>
<xsl:value-of select="." />
</courseorand1>
<xsl:text>
</xsl:text>
</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>
The expected output would look like this:
ACCOUNTING
...
CERTIFICATES
The Accounting certificate requires a minimum of 32 credits in the courses listed below.
ICCB Code 4207 | Field of Study Code: ACCOU.CER.
Accou 1140 Financial Accounting............................................4
Accou 1150 Managerial Accounting...........................................4
Accou 1175 Microcomputer Accounting .......................................2
Accou 2205 Federal Taxation I .............................................3
OR
Accou 2251 Cost Accounting.................................................3
OR
Accou 2200 Income Tax Return Preparation ..................................3
Busin 1100 Introduction to Business .......................................3
Cis 1150 Introduction to Computer Information Systems .....................3
OR
Cis 1110 Using Computers: An Introduction..................................2
Cis 1221 Introduction to Spreadsheets .....................................3
Engli 1101 English Composition 1...........................................3
Math 1100 Business Mathematics.............................................3
Ofti 1100 Introduction to Computer Keyboarding ............................2
Ofti 1210 Word Processing I................................................3
Here is a sample of the XML containing OR and AND elements:
<?xml version="1.0" encoding="UTF-8"?>
<CrystalReport>
<Group Level="1">
<Group Level="2">
<Group Level="3">
<Details Level="4">
<Section SectionNumber="0">
<ACPGDEGREE1/>
<CCD11>ACAC</CCD11>
<ACPGCOMMENTS1>The Accounting certificate requires a minimum 32 credits in the courses listed below.</ACPGCOMMENTS1>
<ICCB1>4207</ICCB1>
<ACADPROGRAMSID1>ACCOU.CER</ACADPROGRAMSID1>
<CRSNO1>1110</CRSNO1>
<ACPGHOMELANGNOTREQDRSN1/>
<CRSMINCRED1>2</CRSMINCRED1>
<ACPGAREAOFSTUDY1>Accounting</ACPGAREAOFSTUDY1>
<CRSTITLE1>Using Computers: An Introduction</CRSTITLE1>
<DEPARTMENT11>ACCOU</DEPARTMENT11>
<ACRBLABEL1>ADDL REQD COURSES</ACRBLABEL1>
<CRSMAXCRED1/>
<FlagElectives1>N</FlagElectives1>
<CRSSUBJECT1>CIS</CRSSUBJECT1>
<COURSEORAND1>OR</COURSEORAND1>
<GROUPORAND1>AND</GROUPORAND1>
<ACADREQMTBLOCKSID1>16324</ACADREQMTBLOCKSID1>
<GROUPLABEL1>Group 2</GROUPLABEL1>
</Section>
</Details>
<Details Level="4">
<Section SectionNumber="0">
<ACPGDEGREE1/>
<CCD11>ACAC</CCD11>
<ACPGCOMMENTS1>The Accounting certificate requires a minimum 32 credits in the courses listed below.</ACPGCOMMENTS1>
<ICCB1>4207</ICCB1>
<ACADPROGRAMSID1>ACCOU.CER</ACADPROGRAMSID1>
<CRSNO1>1150</CRSNO1>
<ACPGHOMELANGNOTREQDRSN1/>
<CRSMINCRED1>3</CRSMINCRED1>
<ACPGAREAOFSTUDY1>Accounting</ACPGAREAOFSTUDY1>
<CRSTITLE1>Intro to Computer Information Systems</CRSTITLE1>
<DEPARTMENT11>ACCOU</DEPARTMENT11>
<ACRBLABEL1>ADDL REQD COURSES</ACRBLABEL1>
<CRSMAXCRED1/>
<FlagElectives1>N</FlagElectives1>
<CRSSUBJECT1>CIS</CRSSUBJECT1>
<COURSEORAND1>OR</COURSEORAND1>
<GROUPORAND1>AND</GROUPORAND1>
<ACADREQMTBLOCKSID1>16324</ACADREQMTBLOCKSID1>
<GROUPLABEL1>Group 2</GROUPLABEL1>
</Section>
</Details>
<Details Level="4">
<Section SectionNumber="0">
<ACPGDEGREE1/>
<CCD11>ACAC</CCD11>
<ACPGCOMMENTS1>The Accounting certificate requires a minimum 32 credits in the courses listed below.</ACPGCOMMENTS1>
<ICCB1>4207</ICCB1>
<ACADPROGRAMSID1>ACCOU.CER</ACADPROGRAMSID1>
<CRSNO1>2200</CRSNO1>
<ACPGHOMELANGNOTREQDRSN1/>
<CRSMINCRED1>3</CRSMINCRED1>
<ACPGAREAOFSTUDY1>Accounting</ACPGAREAOFSTUDY1>
<CRSTITLE1>Income Tax Return Preparation</CRSTITLE1>
<DEPARTMENT11>ACCOU</DEPARTMENT11>
<ACRBLABEL1>ADDL REQD COURSES</ACRBLABEL1>
<CRSMAXCRED1/>
<FlagElectives1>N</FlagElectives1>
<CRSSUBJECT1>ACCOU</CRSSUBJECT1>
<COURSEORAND1>OR</COURSEORAND1>
<GROUPORAND1>AND</GROUPORAND1>
<ACADREQMTBLOCKSID1>16324</ACADREQMTBLOCKSID1>
<GROUPLABEL1>Group 1</GROUPLABEL1>
</Section>
</Details>
<Details Level="4">
<Section SectionNumber="0">
<ACPGDEGREE1/>
<CCD11>ACAC</CCD11>
<ACPGCOMMENTS1>The Accounting certificate requires a minimum 32 credits in the courses listed below.</ACPGCOMMENTS1>
<ICCB1>4207</ICCB1>
<ACADPROGRAMSID1>ACCOU.CER</ACADPROGRAMSID1>
<CRSNO1>2205</CRSNO1>
<ACPGHOMELANGNOTREQDRSN1/>
<CRSMINCRED1>3</CRSMINCRED1>
<ACPGAREAOFSTUDY1>Accounting</ACPGAREAOFSTUDY1>
<CRSTITLE1>Federal Taxation I</CRSTITLE1>
<DEPARTMENT11>ACCOU</DEPARTMENT11>
<ACRBLABEL1>ADDL REQD COURSES</ACRBLABEL1>
<CRSMAXCRED1/>
<FlagElectives1>N</FlagElectives1>
<CRSSUBJECT1>ACCOU</CRSSUBJECT1>
<COURSEORAND1>OR</COURSEORAND1>
<GROUPORAND1>AND</GROUPORAND1>
<ACADREQMTBLOCKSID1>16324</ACADREQMTBLOCKSID1>
<GROUPLABEL1>Group 1</GROUPLABEL1>
</Section>
</Details>
<Details Level="4">
<Section SectionNumber="0">
<ACPGDEGREE1/>
<CCD11>ACAC</CCD11>
<ACPGCOMMENTS1>The Accounting certificate requires a minimum 32 credits in the courses listed below.</ACPGCOMMENTS1>
<ICCB1>4207</ICCB1>
<ACADPROGRAMSID1>ACCOU.CER</ACADPROGRAMSID1>
<CRSNO1>2251</CRSNO1>
<ACPGHOMELANGNOTREQDRSN1/>
<CRSMINCRED1>3</CRSMINCRED1>
<ACPGAREAOFSTUDY1>Accounting</ACPGAREAOFSTUDY1>
<CRSTITLE1>Cost Accounting</CRSTITLE1>
<DEPARTMENT11>ACCOU</DEPARTMENT11>
<ACRBLABEL1>ADDL REQD COURSES</ACRBLABEL1>
<CRSMAXCRED1/>
<FlagElectives1>N</FlagElectives1>
<CRSSUBJECT1>ACCOU</CRSSUBJECT1>
<COURSEORAND1>OR</COURSEORAND1>
<GROUPORAND1>AND</GROUPORAND1>
<ACADREQMTBLOCKSID1>16324</ACADREQMTBLOCKSID1>
<GROUPLABEL1>Group 1</GROUPLABEL1>
</Section>
</Details>
</Group>
<Group Level="3">
<Details Level="4">
<Section SectionNumber="0">
<ACPGDEGREE1/>
<CCD11>ACAC</CCD11>
<ACPGCOMMENTS1>The Accounting certificate requires a minimum 32 credits in the courses listed below.</ACPGCOMMENTS1>
<ICCB1>4207</ICCB1>
<ACADPROGRAMSID1>ACCOU.CER</ACADPROGRAMSID1>
<CRSNO1>1101</CRSNO1>
<ACPGHOMELANGNOTREQDRSN1/>
<CRSMINCRED1>3</CRSMINCRED1>
<ACPGAREAOFSTUDY1>Accounting</ACPGAREAOFSTUDY1>
<CRSTITLE1>English Composition 1</CRSTITLE1>
<DEPARTMENT11>ACCOU</DEPARTMENT11>
<ACRBLABEL1>ENGLISH COMPOSITION</ACRBLABEL1>
<CRSMAXCRED1/>
<FlagElectives1>N</FlagElectives1>
<CRSSUBJECT1>ENGLI</CRSSUBJECT1>
<COURSEORAND1>OR</COURSEORAND1>
<GROUPORAND1/>
<ACADREQMTBLOCKSID1>21697</ACADREQMTBLOCKSID1>
<GROUPLABEL1>Group 1</GROUPLABEL1>
</Section>
</Details>
</Group>
<Group Level="3">
<Details Level="4">
<Section SectionNumber="0">
<ACPGDEGREE1/>
<CCD11>ACAC</CCD11>
<ACPGCOMMENTS1>The Accounting certificate requires a minimum 32 credits in the courses listed below.</ACPGCOMMENTS1>
<ICCB1>4207</ICCB1>
<ACADPROGRAMSID1>ACCOU.CER</ACADPROGRAMSID1>
<CRSNO1>1221</CRSNO1>
<ACPGHOMELANGNOTREQDRSN1/>
<CRSMINCRED1>3</CRSMINCRED1>
<ACPGAREAOFSTUDY1>Accounting</ACPGAREAOFSTUDY1>
<CRSTITLE1>Introduction to Spreadsheets</CRSTITLE1>
<DEPARTMENT11>ACCOU</DEPARTMENT11>
<ACRBLABEL1>PROGRAM REQUIREMENTS</ACRBLABEL1>
<CRSMAXCRED1/>
<FlagElectives1>N</FlagElectives1>
<CRSSUBJECT1>CIS</CRSSUBJECT1>
<COURSEORAND1/>
<GROUPORAND1/>
<ACADREQMTBLOCKSID1>23217</ACADREQMTBLOCKSID1>
<GROUPLABEL1>Group 1</GROUPLABEL1>
</Section>
</Details>
<Details Level="4">
<Section SectionNumber="0">
<ACPGDEGREE1/>
<CCD11>ACAC</CCD11>
<ACPGCOMMENTS1>The Accounting certificate requires a minimum 32 credits in the courses listed below.</ACPGCOMMENTS1>
<ICCB1>4207</ICCB1>
<ACADPROGRAMSID1>ACCOU.CER</ACADPROGRAMSID1>
<CRSNO1>1175</CRSNO1>
<ACPGHOMELANGNOTREQDRSN1/>
<CRSMINCRED1>2</CRSMINCRED1>
<ACPGAREAOFSTUDY1>Accounting</ACPGAREAOFSTUDY1>
<CRSTITLE1>Microcomputer Accounting</CRSTITLE1>
<DEPARTMENT11>ACCOU</DEPARTMENT11>
<ACRBLABEL1>PROGRAM REQUIREMENTS</ACRBLABEL1>
<CRSMAXCRED1/>
<FlagElectives1>N</FlagElectives1>
<CRSSUBJECT1>ACCOU</CRSSUBJECT1>
<COURSEORAND1/>
<GROUPORAND1/>
<ACADREQMTBLOCKSID1>23217</ACADREQMTBLOCKSID1>
<GROUPLABEL1>Group 1</GROUPLABEL1>
</Section>
</Details>
<Details Level="4">
<Section SectionNumber="0">
<ACPGDEGREE1/>
<CCD11>ACAC</CCD11>
<ACPGCOMMENTS1>The Accounting certificate requires a minimum 32 credits in the courses listed below.</ACPGCOMMENTS1>
<ICCB1>4207</ICCB1>
<ACADPROGRAMSID1>ACCOU.CER</ACADPROGRAMSID1>
<CRSNO1>1140</CRSNO1>
<ACPGHOMELANGNOTREQDRSN1/>
<CRSMINCRED1>4</CRSMINCRED1>
<ACPGAREAOFSTUDY1>Accounting</ACPGAREAOFSTUDY1>
<CRSTITLE1>Financial Accounting</CRSTITLE1>
<DEPARTMENT11>ACCOU</DEPARTMENT11>
<ACRBLABEL1>PROGRAM REQUIREMENTS</ACRBLABEL1>
<CRSMAXCRED1/>
<FlagElectives1>N</FlagElectives1>
<CRSSUBJECT1>ACCOU</CRSSUBJECT1>
<COURSEORAND1/>
<GROUPORAND1/>
<ACADREQMTBLOCKSID1>23217</ACADREQMTBLOCKSID1>
<GROUPLABEL1>Group 1</GROUPLABEL1>
</Section>
</Details>
<Details Level="4">
<Section SectionNumber="0">
<ACPGDEGREE1/>
<CCD11>ACAC</CCD11>
<ACPGCOMMENTS1>The Accounting certificate requires a minimum 32 credits in the courses listed below.</ACPGCOMMENTS1>
<ICCB1>4207</ICCB1>
<ACADPROGRAMSID1>ACCOU.CER</ACADPROGRAMSID1>
<CRSNO1>1210</CRSNO1>
<ACPGHOMELANGNOTREQDRSN1/>
<CRSMINCRED1>3</CRSMINCRED1>
<ACPGAREAOFSTUDY1>Accounting</ACPGAREAOFSTUDY1>
<CRSTITLE1>Word Processing I</CRSTITLE1>
<DEPARTMENT11>ACCOU</DEPARTMENT11>
<ACRBLABEL1>PROGRAM REQUIREMENTS</ACRBLABEL1>
<CRSMAXCRED1/>
<FlagElectives1>N</FlagElectives1>
<CRSSUBJECT1>OFTI</CRSSUBJECT1>
<COURSEORAND1/>
<GROUPORAND1/>
<ACADREQMTBLOCKSID1>23217</ACADREQMTBLOCKSID1>
<GROUPLABEL1>Group 1</GROUPLABEL1>
</Section>
</Details>
<Details Level="4">
<Section SectionNumber="0">
<ACPGDEGREE1/>
<CCD11>ACAC</CCD11>
<ACPGCOMMENTS1>The Accounting certificate requires a minimum 32 credits in the courses listed below.</ACPGCOMMENTS1>
<ICCB1>4207</ICCB1>
<ACADPROGRAMSID1>ACCOU.CER</ACADPROGRAMSID1>
<CRSNO1>1100</CRSNO1>
<ACPGHOMELANGNOTREQDRSN1/>
<CRSMINCRED1>3</CRSMINCRED1>
<ACPGAREAOFSTUDY1>Accounting</ACPGAREAOFSTUDY1>
<CRSTITLE1>Business Mathematics</CRSTITLE1>
<DEPARTMENT11>ACCOU</DEPARTMENT11>
<ACRBLABEL1>PROGRAM REQUIREMENTS</ACRBLABEL1>
<CRSMAXCRED1/>
<FlagElectives1>N</FlagElectives1>
<CRSSUBJECT1>MATH</CRSSUBJECT1>
<COURSEORAND1/>
<GROUPORAND1/>
<ACADREQMTBLOCKSID1>23217</ACADREQMTBLOCKSID1>
<GROUPLABEL1>Group 1</GROUPLABEL1>
</Section>
</Details>
</Group>
</Group>
</Group>
</CrystalReport>