954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Selecting multiple attributes with XSL


Day
Instructor
Class

NewbieProgram
Newbie Poster
8 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
 

Because you actually made an effort to solve the problem yourself, and you have the right idea, I'll happily provide you with a solution. It's not the only solution, but it should give you the right ideas. Just put the result in an html document and you'll see it.

Also, please use Codeboxes when posting any of your documents or code.

Input Document

<schedule>
	<student_info>Vitaliy Berkovich 803-401-025</student_info>
	<info>
		<day name="Monday">
			<Class name="Database Administration" Code="CPAN 315" Instructor="Paul Berger" Time="9:00-10:45" Location="E422"/>
			<Class name="Design Patterns and Software Testing" Code="CPAN 311" Instructor="Robert Robson" Time="10:50-12:35" Location="E417"/>
			<Class name="Requirements Analysis and Process Modelling(WI)" Code="CPAN 331" Instructor="Razieh Niazi" Time="2:30-4:15" Location="J129"/>
		</day>
		<day name="Tuesday">
			<Class name="XML" Code="CPAN 330" Instructor="Eric Dymond" Time="9:55-10:45" Location="E422"/>
			<Class name="Design Patterns and Software Testing" Code="CPAN 311" Instructor="Robert Robson" Time="10:50-12:35" Location="J132"/>
			<Class name="Android Programming" Code="CPAN 312" Instructor="Igor Pustylnick" Time="2:30-4:15" Location="E422"/>
		</day>
		<day name="Wednesday">
			<Class name="Open Source Programming" Code="CPAN 332" Instructor="Eric Dymond" Time="9:00-10:45" Location="E417"/>
			<Class name="Android Programming" Code="CPAN 312" Instructor="Igor Pustylnick" Time="11:45-1:30" Location="J132"/>
			<Class name="XML" Code="CPAN 330" Instructor="Eric Dymond" Time="1:35-3:20" Location="J132"/>
		</day>
		<day name="Friday">
			<Class name="Database Administration" Code="CPAN 315" Instructor="Paul Berger" Time="11:45-1:30" Location="J132"/>
			<Class name="Open Source Programming" Code="CPAN 332" Instructor="Eric Dymond" Time="1:35-3:20" Location="J132"/>
			<Class name="Requirements Analysis and Process Modelling(WI)" Code="CPAN 331" Instructor="Razieh Niazi" Time="4:20-6:05" Location="J130"/>
		</day>
	</info>
</schedule>


Transformation

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

	<xsl:template match="/">
		<html>
			<head>
				<title>Schedule</title>
			</head>
			<body>
				<xsl:apply-templates select="schedule"/>
			</body>
		</html>
	</xsl:template>

	<xsl:template match="schedule">
		<xsl:apply-templates select="info"/>
	</xsl:template>

	<xsl:template match="info">
		<table width="100%" border="1">
			<thead>
				<tr>
					<th>Day</th>
					<th>Class</th>
					<th>Instructor</th>					
				</tr>
				<tbody>
					<xsl:apply-templates select="day" />
				</tbody>				
			</thead>
		</table>
	</xsl:template>

	<xsl:template match="day" >
		<xsl:apply-templates select="Class" />
	</xsl:template>

	<xsl:template match="Class">
		<tr>
			<td><xsl:value-of select="../@name"/></td>
			<td><xsl:value-of select="@name"/></td>
			<td><xsl:value-of select="@Instructor"/></td>
		</tr>
	</xsl:template>
</xsl:stylesheet>


Results

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Schedule</title>
  </head>
  <body>
    <table width="100%" border="1">
      <thead>
        <tr>
          <th>Day</th>
          <th>Class</th>
          <th>Instructor</th>
        </tr>
        <tbody>
          <tr>
            <td>Monday</td>
            <td>Database Administration</td>
            <td>Paul Berger</td>
          </tr>
          <tr>
            <td>Monday</td>
            <td>Design Patterns and Software Testing</td>
            <td>Robert Robson</td>
          </tr>
          <tr>
            <td>Monday</td>
            <td>Requirements Analysis and Process Modelling(WI)</td>
            <td>Razieh Niazi</td>
          </tr>
          <tr>
            <td>Tuesday</td>
            <td>XML</td>
            <td>Eric Dymond</td>
          </tr>
          <tr>
            <td>Tuesday</td>
            <td>Design Patterns and Software Testing</td>
            <td>Robert Robson</td>
          </tr>
          <tr>
            <td>Tuesday</td>
            <td>Android Programming</td>
            <td>Igor Pustylnick</td>
          </tr>
          <tr>
            <td>Wednesday</td>
            <td>Open Source Programming</td>
            <td>Eric Dymond</td>
          </tr>
          <tr>
            <td>Wednesday</td>
            <td>Android Programming</td>
            <td>Igor Pustylnick</td>
          </tr>
          <tr>
            <td>Wednesday</td>
            <td>XML</td>
            <td>Eric Dymond</td>
          </tr>
          <tr>
            <td>Friday</td>
            <td>Database Administration</td>
            <td>Paul Berger</td>
          </tr>
          <tr>
            <td>Friday</td>
            <td>Open Source Programming</td>
            <td>Eric Dymond</td>
          </tr>
          <tr>
            <td>Friday</td>
            <td>Requirements Analysis and Process Modelling(WI)</td>
            <td>Razieh Niazi</td>
          </tr>
        </tbody>
      </thead>
    </table>
  </body>
</html>
iceandrews
Junior Poster
185 posts since May 2010
Reputation Points: 10
Solved Threads: 30
 

Thank you, I've been breaking my head for hours!

NewbieProgram
Newbie Poster
8 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You