我有一个 XML 文件,其中列出了学位课程下的课程。我创建了一个 XSLT(在帮助下),它成功地创建了学位名称下的类组。但是客户想要一个识别选修课和非选修课的第三级。如果是选修课,选修课将与数据“Y”一起列出,如果不是选修课,则与“N”一起列出,否则为“程序要求”。
如果元素中有“N”,我需要向 XSLT 添加另一个级别,该级别在标题“程序要求”下对类进行分组<FlagElectives1>
。
我想我需要根据这个元素创建另一个键,对,然后创建一个模板来创建一个 xsl:text 标题,上面写着:“程序要求”或“程序选修”,但我被卡住了。我以前从未做过三级分组。
这是我的 XSLT:
<?xml version="1.0"?>
<!-- DWXMLSource="STX049 Catalog 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:template match="/">
<CrystalReport>
<xsl:apply-templates/>
</CrystalReport>
</xsl:template>
<xsl:key name="degrees-by-title" match="CrystalReport/Group/Group/Group/Details" use="Section/ICCB1" />
<xsl:template match="CrystalReport/Group/Group/Group">
<Degree>
<xsl:for-each select="Details[count(. | key('degrees-by-title', Section/ICCB1)[1]) = 1]">
<xsl:sort select="Section/ACADPROGRAMSID1" />
<department>
<Degreetitle>
<xsl:apply-templates select="Section/ACPGDEGREE1" />
</Degreetitle>
<Certtitle>
<xsl:apply-templates select="Section/CCD11" />
</Certtitle>
<DegreeDesc>
<xsl:value-of select="Section/ACPGCOMMENTS1"/>
</DegreeDesc>
<ICCBcode>
<xsl:value-of select="Section/ICCB1"/>
</ICCBcode>
<ProgramID>
<xsl:value-of select="Section/ACADPROGRAMSID1"/>
</ProgramID>
<xsl:for-each select="key('degrees-by-title', Section/ICCB1)">
<xsl:sort select="Section/FlagElectives1" order="ascending" />
<xsl:sort select="Section/DEPARTMENT11" />
<xsl:sort select="Section/CRSNO1" />
<Details>
<class>
<deptname>
<xsl:value-of select="Section/DEPARTMENT11"/>
</deptname>
<courseno>
<xsl:value-of select="Section/CRSNO1"/>
</courseno>
<classname>
<xsl:value-of select="Section/CRSTITLE1"/>
</classname>
<classcredit>
<xsl:value-of select="Section/CRSMINCRED1"/>
</classcredit>
<Elective>
<xsl:value-of select="Section/FlagElectives1" />
</Elective>
</class>
</Details>
</xsl:for-each>
</department>
</xsl:for-each>
</Degree>
</xsl:template>
<xsl:template match="Section/ACPGDEGREE1[child::node()]">
<xsl:value-of select="."/>
<xsl:text> DEGREE</xsl:text>
</xsl:template>
<xsl:template match="Section/CCD11[child::node()]">
<xsl:text> CERTIFICATE</xsl:text>
</xsl:template>
</xsl:stylesheet>
这是我的 XML 的结构:
<?xml version="1.0" encoding="UTF-8"?>
<CrystalReport>
<Group Level="1">
<Group Level="2">
<Group Level="3">
<Details>
<Section>
<ACPGDEGREE1>AAS</ACPGDEGREE1>
<CCD11/>
<ACPGCOMMENTS1>The Accounting program</ACPGCOMMENTS1>
<ICCB1>3203</ICCB1>
<ACADPROGRAMSID1>ACCOU.AAS</ACADPROGRAMSID1>
<CRSNO1>1110</CRSNO1>
<ACRBPRINTEDSPEC1/>
<ACPGHOMELANGNOTREQDRSN1>General Education</ACPGHOMELANGNOTREQDRSN1>
<CRSMINCRED1>2</CRSMINCRED1>
<ACPGAREAOFSTUDY1>Accounting</ACPGAREAOFSTUDY1>
<CRSTITLE1>Using Computers: An Introduction</CRSTITLE1>
<DEPARTMENT11>ACCOU</DEPARTMENT11>
<CRSSUBJECT1>CIS</CRSSUBJECT1>
<ACRBLABEL1>CIS REQUIREMENT</ACRBLABEL1>
<CRSMAXCRED1/>
<FlagElectives1>N</FlagElectives1>
</Section>
</Details>
<Details>
<Section>
<ACPGDEGREE1>AAS</ACPGDEGREE1>
<CCD11/>
<ACPGCOMMENTS1>The Accounting program</ACPGCOMMENTS1>
<ICCB1>3203</ICCB1>
<ACADPROGRAMSID1>ACCOU.AAS</ACADPROGRAMSID1>
<CRSNO1>1150</CRSNO1>
<ACRBPRINTEDSPEC1/>
<ACPGHOMELANGNOTREQDRSN1>General Education</ACPGHOMELANGNOTREQDRSN1>
<CRSMINCRED1>3</CRSMINCRED1>
<ACPGAREAOFSTUDY1>Accounting</ACPGAREAOFSTUDY1>
<CRSTITLE1>Intro to Computer</CRSTITLE1>
<DEPARTMENT11>ACCOU</DEPARTMENT11>
<CRSSUBJECT1>CIS</CRSSUBJECT1>
<ACRBLABEL1>CIS</ACRBLABEL1>
<CRSMAXCRED1/>
<FlagElectives1>Y</FlagElectives1>
</Section>
</Details>
</Group>
</Group>
</Group>
</CrystalReport>
第一级分组应该基于元素<DEPARTMENT11>
。各种学位和证书的标题在字段<ACPGAREAOFSTUDY1>
中找到所有这一切中的第二级唯一字段是<ACADPROGRAMSID1>
这是所需的输出:
<CrystalReport>
<Degrees>
<!--group and repeat "Degrees" for-each based on element ACPGAREAOFSTUDY1-->
<areaofstudy>Accounting</areaofstudy>
<Degree>
<department>
<!--group and repeat "department" for-each based on element ICCB1-->
<Degreetitle>AAS DEGREE</Degreetitle>
<Certtitle />
<DegreeDesc>The Accounting program</DegreeDesc>
<ICCBcode>3203</ICCBcode>
<ProgramID>ACCOU.AAS</ProgramID>
<!--group and repeat "Details" for-each based on element ACADPROGRAMSID1 under titles "Program Requirement" or "Program Elective" based on element "FlagElectives1"-->
<h1>Program Requirements</h1>
<Details>
<class>
<deptname>ACCOU</deptname>
<courseno>1150</courseno>
<classname>Intro to Computer</classname>
<classcredit>3</classcredit>
<Elective>N</Elective>
</class>
</Details>
<h1>Program Electives</h1>
<Details>
<class>
<deptname>ACCOU</deptname>
<courseno>1110</courseno>
<classname>Using Computers: An Introduction</classname>
<classcredit>2</classcredit>
<Elective>Y</Elective>
</class>
</Details>
</department>
</Degree>
<Degree>
<department>
<Degreetitle>AAS DEGREE</Degreetitle>
<Certtitle />
<DegreeDesc>The Accounting program</DegreeDesc>
<ICCBcode>3203</ICCBcode>
<ProgramID>ACCOU.AAS</ProgramID>
<h1>Program Requirements</h1>
<Details>
<class>
<deptname>ACCOU</deptname>
<courseno>1150</courseno>
<classname>Intro to Computer</classname>
<classcredit>3</classcredit>
<Elective>Y</Elective>
</class>
</Details>
<h1>Program Electives</h1>
<Details>
<class>
<deptname>ACCOU</deptname>
<courseno>1110</courseno>
<classname>Using Computers: An Introduction</classname>
<classcredit>2</classcredit>
<Elective>N</Elective>
</class>
</Details>
</department>
</Degree>
</Degrees>
</CrystalReport>