1

我的 XSLT 为这个大学目录创建了三个级别的分组。我需要再添加一个级别来识别可选类并将它们组合在一起。

第一级组在第二级<ACPGAREAOFSTUDY1>组上<ACPGDEGREE1>和第三级组上<ICCB1>

第四级基于四个要素:<COURSEORAND1> <GROUPORAND1> <ACADREQMTBLOCKSID1><GROUPLABEL1>

这是最终分组的逻辑

当 COURSEORAND1 说“或”时,GROUPORAND1 为空。-这意味着有两个或多个课程可供选择,它会输出“OR”</p>

当 COURSEORAND1 说“OR”时,GROUPORAND1 说“AND”。- 这意味着它将为组中的 2 门课程输出“或”。这也意味着它将为组输出“AND”。

课程可以按元素 ACADREQMTBLOCKSID1 分组,这些组可以按 GROUPLABEL1 分组。

这是当前的 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>&#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: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>&#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">
        <xsl:text>&#xA;</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>&#xA;</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>&#xA;</xsl:text>
  </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>

预期的输出如下所示:

 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

以下是包含 OR 和 AND 元素的 XML 示例:

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

0 回答 0