0

我有一个 XSLT,它正在创建一个数据显示,按学科、学位和班级对大学课程进行分组。

XSLT 不知何故创建了重复数据。每当元素<COURSEORAND1><GROUPORAND1>为空时,它都会重复该类列表一次或多次(至少这是我的猜测)。在某些情况下,它会创建十几个重复项。该类仅在基础 XML 中出现一次。

我不知道是什么导致 XSLT 复制数据。

这是 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="GROUPLABEL1" />
        <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>
      <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>

这是 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>AAS</ACPGDEGREE1>
            <CCD11/>
            <ACPGCOMMENTS1>The Accounting program is designed to provide the theoretical and practical background necessary for supervisory and administrative careers in accounting and accounting-related areas. This degree requires a minimum of 64 credits in program requirements, program electives, and general education as listed below.</ACPGCOMMENTS1>
            <ICCB1>3203</ICCB1>
            <ACADPROGRAMSID1>ACCOU.AAS</ACADPROGRAMSID1>
            <CRSNO1>1150</CRSNO1>
            <ACPGHOMELANGNOTREQDRSN1>General Education - 12 to 16 credit hours (In addition to those listed above)  Total Credits Required - 64 to 70</ACPGHOMELANGNOTREQDRSN1>
            <CRSMINCRED1>3</CRSMINCRED1>
            <ACPGAREAOFSTUDY1>Accounting</ACPGAREAOFSTUDY1>
            <CRSTITLE1>Intro to Computer Information Systems</CRSTITLE1>
            <DEPARTMENT11>ACCOU</DEPARTMENT11>
            <ACRBLABEL1>CIS REQUIREMENT</ACRBLABEL1>
            <CRSMAXCRED1/>
            <FlagElectives1>N</FlagElectives1>
            <CRSSUBJECT1>CIS</CRSSUBJECT1>
            <COURSEORAND1>OR</COURSEORAND1>
            <GROUPORAND1/>
            <ACADREQMTBLOCKSID1>16316</ACADREQMTBLOCKSID1>
            <GROUPLABEL1>Group 1</GROUPLABEL1>
          </Section>
        </Details>
        <Details Level="4">
          <Section SectionNumber="0">
            <ACPGDEGREE1>AAS</ACPGDEGREE1>
            <CCD11/>
            <ACPGCOMMENTS1>The Accounting program is designed to provide the theoretical and practical background necessary for supervisory and administrative careers in accounting and accounting-related areas. This degree requires a minimum of 64 credits in program requirements, program electives, and general education as listed below.</ACPGCOMMENTS1>
            <ICCB1>3203</ICCB1>
            <ACADPROGRAMSID1>ACCOU.AAS</ACADPROGRAMSID1>
            <CRSNO1>1110</CRSNO1>
            <ACPGHOMELANGNOTREQDRSN1>General Education - 12 to 16 credit hours (In addition to those listed above)  Total Credits Required - 64 to 70</ACPGHOMELANGNOTREQDRSN1>
            <CRSMINCRED1>2</CRSMINCRED1>
            <ACPGAREAOFSTUDY1>Accounting</ACPGAREAOFSTUDY1>
            <CRSTITLE1>Using Computers: An Introduction</CRSTITLE1>
            <DEPARTMENT11>ACCOU</DEPARTMENT11>
            <ACRBLABEL1>CIS REQUIREMENT</ACRBLABEL1>
            <CRSMAXCRED1/>
            <FlagElectives1>N</FlagElectives1>
            <CRSSUBJECT1>CIS</CRSSUBJECT1>
            <COURSEORAND1>OR</COURSEORAND1>
            <GROUPORAND1/>
            <ACADREQMTBLOCKSID1>16316</ACADREQMTBLOCKSID1>
            <GROUPLABEL1>Group 1</GROUPLABEL1>
          </Section>
        </Details>
      </Group>
      <Group Level="3">
        <Details Level="4">
          <Section SectionNumber="0">
            <ACPGDEGREE1>AAS</ACPGDEGREE1>
            <CCD11/>
            <ACPGCOMMENTS1>The Accounting program is designed to provide the theoretical and practical background necessary for supervisory and administrative careers in accounting and accounting-related areas. This degree requires a minimum of 64 credits in program requirements, program electives, and general education as listed below.</ACPGCOMMENTS1>
            <ICCB1>3203</ICCB1>
            <ACADPROGRAMSID1>ACCOU.AAS</ACADPROGRAMSID1>
            <CRSNO1>1100</CRSNO1>
            <ACPGHOMELANGNOTREQDRSN1>General Education - 12 to 16 credit hours (In addition to those listed above)  Total Credits Required - 64 to 70</ACPGHOMELANGNOTREQDRSN1>
            <CRSMINCRED1>2</CRSMINCRED1>
            <ACPGAREAOFSTUDY1>Accounting</ACPGAREAOFSTUDY1>
            <CRSTITLE1>Introduction to Computer Keyboarding</CRSTITLE1>
            <DEPARTMENT11>ACCOU</DEPARTMENT11>
            <ACRBLABEL1>OFTI REQUIREMENT</ACRBLABEL1>
            <CRSMAXCRED1/>
            <FlagElectives1>N</FlagElectives1>
            <CRSSUBJECT1>OFTI</CRSSUBJECT1>
            <COURSEORAND1>OR</COURSEORAND1>
            <GROUPORAND1/>
            <ACADREQMTBLOCKSID1>16318</ACADREQMTBLOCKSID1>
            <GROUPLABEL1>Group 1</GROUPLABEL1>
          </Section>
        </Details>
        <Details Level="4">
          <Section SectionNumber="0">
            <ACPGDEGREE1>AAS</ACPGDEGREE1>
            <CCD11/>
            <ACPGCOMMENTS1>The Accounting program is designed to provide the theoretical and practical background necessary for supervisory and administrative careers in accounting and accounting-related areas. This degree requires a minimum of 64 credits in program requirements, program electives, and general education as listed below.</ACPGCOMMENTS1>
            <ICCB1>3203</ICCB1>
            <ACADPROGRAMSID1>ACCOU.AAS</ACADPROGRAMSID1>
            <CRSNO1>1210</CRSNO1>
            <ACPGHOMELANGNOTREQDRSN1>General Education - 12 to 16 credit hours (In addition to those listed above)  Total Credits Required - 64 to 70</ACPGHOMELANGNOTREQDRSN1>
            <CRSMINCRED1>3</CRSMINCRED1>
            <ACPGAREAOFSTUDY1>Accounting</ACPGAREAOFSTUDY1>
            <CRSTITLE1>Word Processing I</CRSTITLE1>
            <DEPARTMENT11>ACCOU</DEPARTMENT11>
            <ACRBLABEL1>OFTI REQUIREMENT</ACRBLABEL1>
            <CRSMAXCRED1/>
            <FlagElectives1>N</FlagElectives1>
            <CRSSUBJECT1>OFTI</CRSSUBJECT1>
            <COURSEORAND1>OR</COURSEORAND1>
            <GROUPORAND1/>
            <ACADREQMTBLOCKSID1>16318</ACADREQMTBLOCKSID1>
            <GROUPLABEL1>Group 1</GROUPLABEL1>
          </Section>
        </Details>
      </Group>
    </Group>
  </Group>
</CrystalReport>

注意:XML 只是一个小示例,我在此链接中放置了一个较大的示例:http: //pastebin.com/Y4J2VDRd

我注意到它只有在运行整个文件时才会发生。较短的样本不会重复。但是,如果您在 Pastebin 上查看我的示例,您会看到<courseno>1175</courseno> <classname>Microcomputer Accounting</classname><courseno>1100</courseno> <classname>Business Mathematics</classname>重复两次,在更大的 XML 中,您会看到随着您深入数据,类会重复多次。

这是预期的文本输出:

 AAS DEGREE
 The Accounting degree program is designed to provide the theoretical and practical background necessary for supervisory and administrative careers in accounting and accounting-related areas. This degree program requires a minimum of 64 credits in program requirements, program electives and general education as listed below.
 ICCB Code 3203 | Field of Study Code: ACCOU.AAS
 Program Requirements
 Accou 1140 Financial Accounting............................................4
 Accou 1150 Managerial Accounting...........................................4
 Accou 2205 Federal Taxation I .............................................3
 Accou 2241 Intermediate Accounting I.......................................4
 Accou 2242 Intermediate Accounting II......................................4
 Accou 2251 Cost Accounting.................................................3
 Busin 1100 Introduction to Business .......................................3
 Cis 1150 Introduction to Computer Information Systems .....................3
 OR
 Cis 1110 Using Computers: An Introduction..................................2
 Econo 2201 Macroeconomics and the Global Economy ..........................3
 Ofti 1100 Introduction to Computer Keyboarding ............................2
 OR
 Ofti 1210 Word Processing I................................................3
 Philo 1114 Business Ethics ................................................3
 (Total Credits)   35
4

1 回答 1

0

事实证明,数据确实重复了多次。感谢您查看此问题。我们正在努力生成新数据。

于 2013-03-12T07:09:40.680 回答