Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9229557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:36:05+00:00 2026-06-18T05:36:05+00:00

I have an XML file that lists classes under a degree program. I have

  • 0

I have an XML file that lists classes under a degree program. I have created a XSLT (with help) that successfully creates groups of classes under the degree name. But the client wants a third level that identifies elective and non-elective classes. The elective field is listed with the data “Y” if it is an elective and “N” if is not, or otherwise a “program requirement”.

I need to add another level to the XSLT that groups classes under a title “Program Requirement” if it has an “N” in the element <FlagElectives1>.

I think I need to create another key based on this element, right, and then create a template that creates a xsl:text title that says either: “Program Requirement” or “Program Elective” but I am stuck. I’ve never done three-level grouping before.

Here’s my 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>

Here is the structure of my 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>

The first level of grouping should be based on the element <DEPARTMENT11>. The title of the various degrees and certificates is found in the field <ACPGAREAOFSTUDY1>
The second level unique field in all this is <ACADPROGRAMSID1>

Here is the desired output:

<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>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T05:36:06+00:00Added an answer on June 18, 2026 at 5:36 am

    I did a bit of cleanup on your XSLT. Any time you have a for-each nested inside a for-each, that’s a good sign that your XSLT needs some refactoring. I think I’ve understood what you mean by grouping the courses by whether they are electives or not (though you haven’t indicated how you want to represent that), so what I came up with is the following:

    <?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: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" />
        <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" />
        <xsl:text>&#xA;</xsl:text>
        <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>
          <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: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>
        </department>
      </xsl:template>
    
      <xsl:template name="CourseGroup">
        <xsl:param name="courses" />
        <xsl:param name="title" />
    
        <xsl:if test="$courses">
          <xsl:text>&#xA;</xsl:text>
          <xsl:value-of select="$title" />
          <xsl:apply-templates select="$courses">
            <xsl:sort select="FlagElectives1" order="ascending" />
            <xsl:sort select="DEPARTMENT11" />
            <xsl:sort select="CRSNO1" />
          </xsl:apply-templates>
        </xsl:if>
      </xsl:template>
    
      <xsl:template match="Section">
        <xsl:text>&#xA;</xsl:text>
        <Details>
          <class>
            <deptname>
              <xsl:apply-templates select="DEPARTMENT11" />
            </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>
          </class>
        </Details>
      </xsl:template>
    
      <xsl:template match="ACPGDEGREE1/text()">
        <xsl:value-of select="concat(., ' DEGREE')"/>
      </xsl:template>
    
      <xsl:template match="CCD11/text()">
        <xsl:value-of select="concat(., ' CERTIFICATE')" />
      </xsl:template>
    </xsl:stylesheet>
    

    The elective grouping is achieved through the call-template items, that select courses by whether or not they are electives:

      <xsl:variable name="courses" 
                    select="key('degrees-by-title', ICCB1)" />
      <xsl:call-template name="CourseGroup">
        <xsl:with-param name="courses" select="$courses[FlagElectives1 = 'Y']" />
        <xsl:with-param name="title" select="'Program Requirements'" />
      </xsl:call-template>
    

    When run on your sample input, this XSLT produces:

    <CrystalReport>
      <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>
    </CrystalReport>
    

    Note the h1 elements noting the start of the requirement and elective groups. If you would like this represented some other way, please clarify that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML file that lists a series of items, and the items
I have an XML file that looks like <?xml version=1.0> <playlist> <name>My Playlist</name> <song>
I have an XML file that reads like this <abc> <ab>value</ab> <aa>time</aa> <ac>money</ac> </abc>
I have an XML file that I'm trying to read from here , and
I have an XML file that is well formed and valid (matched with an
I have an XML file that looks like <?xml version='1.0' encoding='UTF-8'?> <root> <node name=foo1
I have an XML file that has a number of nodes, each of which
I have an XML file that is very long, but here is a shot
I have an XML file that I'm trying to serialize into an object. Some
I have an xml file that I want to configure using a bash script.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.