I need help trying to get the majors "CSAT" and "ISAS" into the Majors/Concentration column and then have the corresponding course numbers with commas. Any Help

XML Code

<?xml version="1.0"?>
  
<!-- coursinfo.xml, uses three XSLT stlyesheets to create 
the desired view of the data ITEC 325 - assignment -->



<?xml-stylesheet type="text/xsl" href="conclist.xsl"?>



<itec>
  <course number='324'>
    <title>Principles of CS III</title>
    <majors>
      <mj dg='CSAT'>
	 <co>CS</co>
	 <co>DB</co>
	 <co>SE</co>
	 <co>NET</co>
      </mj>
      <mj dg='ISAS'>
      <!--list any concentrations that apply -->
      </mj>
   </majors>
 </course>
</itec>

XSLT Code

<?xml version="1.0" ?> 
<!--  consclist.xsl 
  --> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" />
<xsl:template match="/">
<html>
   <head>
     <style type="text/css">table {background-color:lightgray; border-style:solid; border-color:red; border-width:10px; } 
	caption {font-weight:bold; font-size:16pt; }
     </style>
   </head>
   <body>
     <table border ="2" cellpadding = "5">
       <tr>
          <th>Major/Area of Concentration</th>
	  <th>Required ITEC Courses</th>
       </tr>
     <xsl:for-each select="itec/course">
     <xsl:sort select="majors/mj" data-type="text" order="ascending" />
     <xsl:sort select="majors/co" data-type="text" 			order="ascending" />
     <xsl:sort select="@number" data-type="number" order="descending" />
	<tr>

	  <td>
	     <xsl:text>/</xsl:text>
	     <xsl:value-of select="majors/mj" />	     
	  </td>

	  <td>
	     <xsl:value-of select="@number" />
	  </td>

	</tr>
     </xsl:for-each>
     </table>
    </body>
</html>
</xsl:template>
</xsl:stylesheet>

instead of sort selects try using xsl:when and xsl: otherwise, think that should work in this case.

I am not sure what you mean. Could you show me?

I have been beating my head on this now for a day and do not know what is wrong. Anyone have any thoughts?

The problem is that you haven't provided us with a defined output. Based off your input document, actually build the HTML result page that your desire. Then we can clearly see the mappings from the input to the ouput, and provide a solution.

"I need help trying to get the majors "CSAT" and "ISAS" into the Majors/Concentration column and then have the corresponding course numbers with commas. Any Help" isn't much of a description of the ouput. Yes we can see what you're trying to do in your transformation you provided, but it's not clear.

Produce the output document, and I'll solve it.

this is what i need. It is two columns of a table
Major/Area of Concentration Required ITEC Courses
CSAT/CS 420, 380,371,370,360,352,324,320
CSAT/DB 442, 441,340,325,324,320
CSAT/NET …
CSAT/SE …
ISAS/IS …

This is actually a really complicated grouping problem. (Google: xslt 1.0 manchurian grouping ) There is no simple solution to get what you want (especially in XSLT 1.0).

Question: Is the list of Majors/Areas of Concentration fixed? In other words could you construct a fixed list of Majors (CSAT, ISAS, etc, etc) and the concentrations that go with them (CSAT = CS,DB,SE,NET,etc etc / ISAS = XX,YY,etc,etc) ? If you can do that I could come up with a relatively straight forward solution using a look-up table. If they are totally dynamic....well, it's a tough problem.

that is all the major and concentrations. I just need to put the course numbers that correspond with that concentration.

I dont know if this will help you but here is what i am using for my courses.

Perfect. Give me some time. I'll try and work something up!

Thanks this shouldnt be to bad but i just can not figure it out since this is a beginner level XML assignmnet.

If you could help me with the last column on this one, if you have time. Here is what the three column of the table need to look like i have the frist two correct. I had to put them on top of each other so it would look right but its on table with three columns

ITEC Courses
ITEC 310

ITEC 315

ITEC 320

Course Title
Programming in C and Unix

Graphical User Interfaces

Procedural Analysis and Design

Majors/Concentrations
that require:
CSAT – NET
ISAS - None

CSAT – None
ISAS - Web

CSAT – CS,DB,SE
ISAS - None


XSLT Code

<?xml version="1.0" ?> 
<!--  crslist.xsl 
  --> 
<xsl:stylesheet version="1.0" 

xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" />
<xsl:template match="/">
<html>
   <head>
     <style type="text/css">table {background-color:lightgray; 	

border-style:solid; border-color:red; border-width:10px; } 
	caption {font-weight:bold; font-size:16pt; }
     </style>
   </head>
   <body>

     <table border ="2" cellpadding = "5">
       <tr>
          <th>ITEC Courses</th>
	  <th>Course Title</th>
	  <th>Major/Concentration that require:</th>            
       </tr>

     <xsl:for-each select="itec/course">
     <xsl:sort select="@number" data-type="number" order="ascending" />

       <tr>

	  <td>
	     <xsl:text>ITEC </xsl:text>
	     <xsl:value-of select="@number" />
	     <xsl:text/>
	  </td>

	  <td>
	     <xsl:value-of select="title" />
	     <xsl:text/>
	  </td>

	  <td>  
	    
		<xsl:text>CSAT</xsl:text>
		<xsl:text>-</xsl:text>

	     <xsl:apply-templates select="majors//co"/>
	     
		<xsl:choose>
  		  <xsl:when test="position()= last()"/> 
  		  <xsl:otherwise>
		     <xsl:text>,</xsl:text>
		  </xsl:otherwise> 
		  
  		</xsl:choose>
	   
	  </td>

       </tr>
     </xsl:for-each>

Okay, here's a solution. Not sure if it will work for you, but it's the best I can do without doing a major grouping exercise. It's also the best I can do on short notice.

So the idea here is that the list of Majors and Concentrations is fixed. There won't be a course that isn't in one of the Majors/Concentrations that you've provided in the course list document. Because of this I can construct a static look-up table to use as as point of reference for my transformation. The look-up table (and filename) that I constructed is as follows:

Look-Up Table - "concsLUT.xml"

<concentrations>
	<conc major="CSAT">CS</conc>
	<conc major="CSAT">DB</conc>
	<conc major="CSAT">SE</conc>
	<conc major="CSAT">NET</conc>
	<conc major="ISAS">IS</conc>
	<conc major="ISAS">WEB</conc>
</concentrations>

So instead of using your standard course list document that you described, I'm going to up this look-up table as my guide. For each major/conc combination (eg CSAT/CS), I'm going to search for a course. Once I find one course I'm going to grab that number, and look for another course, and grabs its number. This will continue until there aren't any more courses that match that major/conc combo (CSAT/CS). Once I'm done with 1 combo, I'll go to the next.

all the documents I used to test and include are below. Note the variable I've created in the transformation that uses "document()" to bring in the look-up table I need.

It should be noted this is pretty ugly :) I could do a cleaner solution that doesn't depend on a LUT, but that would take time I don't have. Good luck.

Input

<itec>
	<course number="324">
		<title>Principles of CS III</title>
		<majors>
			<mj dg="CSAT">
				<co>CS</co>
				<co>DB</co>
				<co>SE</co>
				<co>NET</co>
			</mj>
			<mj dg="ISAS">
			</mj>
		</majors>
	</course>
	<course number="350">
		<title>Intro to CN</title>
		<majors>
			<mj dg="CSAT">
				<co>NET</co>				
			</mj>
			<mj dg="ISAS">
				<co>WEB</co>
			</mj>
		</majors>
	</course>
	<course number="340">
		<title>Database I</title>
		<majors>
			<mj dg="CSAT">
				<co>DB</co>
				<co>NET</co>
			</mj>
			<mj dg="ISAS">
				<co>IS</co>
				<co>WEB</co>
			</mj>
		</majors>
	</course>
</itec>

Transformation

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output indent="yes" method="html"/>

	<xsl:variable name="cLUT" select="document('concsLUT.xml')/concentrations"/>

	<xsl:template match="/">
		<html>
			<head>
				<style type="text/css">table {background-color:lightgray; border-style:solid; border-color:red; border-width:10px; } 
	caption {font-weight:bold; font-size:16pt; }</style>
			</head>
			<body>
				<table border="2" cellpadding="5">
					<tr>
						<th>Major/Area of Concentration</th>
						<th>Required ITEC Courses</th>
					</tr>
					<xsl:variable name="rootcontext" select="/"/>
					<xsl:for-each select="$cLUT/conc">
						<tr>
							<td>
								<xsl:value-of select="concat(@major,'/',.)"/>
							</td>
							<td>
								<xsl:variable name="major" select="@major"/>
								<xsl:variable name="conc" select="."/>
								<xsl:for-each select="$rootcontext//course[majors/mj[@dg = $major]/co[. = $conc]]">
									<xsl:sort select="./@number"/>
									<xsl:value-of select="@number"/>														
									<xsl:if test="position() != last()">
										<xsl:text>, </xsl:text>
									</xsl:if>
								</xsl:for-each>
							</td>
						</tr>
					</xsl:for-each>
				</table>
			</body>
		</html>
	</xsl:template>
</xsl:stylesheet>

Output HTML Code

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html">
    <style type="text/css">table {background-color:lightgray; border-style:solid; border-color:red; border-width:10px; } 
	caption {font-weight:bold; font-size:16pt; }
    </style>
  </head>
  <body>
    <table border="2" cellpadding="5">
      <tr>
        <th>Major/Area of Concentration</th>
        <th>Required ITEC Courses</th>
      </tr>
      <tr>
        <td>CSAT/CS</td>
        <td>324</td>
      </tr>
      <tr>
        <td>CSAT/DB</td>
        <td>324, 340</td>
      </tr>
      <tr>
        <td>CSAT/SE</td>
        <td>324</td>
      </tr>
      <tr>
        <td>CSAT/NET</td>
        <td>324, 340, 350</td>
      </tr>
      <tr>
        <td>ISAS/IS</td>
        <td>340</td>
      </tr>
      <tr>
        <td>ISAS/WEB</td>
        <td>340, 350</td>
      </tr>
    </table>
  </body>
</html>

Thanks a lot that really helped. Any way you could take a look at the one right before the code you posted?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.