XSL Style Sheet Help

Putting Together A Table

Page 1 of 1

6 Replies - 1296 Views - Last Post: 17 November 2009 - 01:39 PM

#1 BasementArtScott  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 49
  • Joined: 11-July 09

XSL Style Sheet Help

Posted 16 November 2009 - 10:29 AM

I am working on creating a table to hold classroom data. I have it all, but complete, but cannot figure out how to get my style sheet to work.

Here is the xml portion of the table

<?xml version="1.0" encoding="UTF-8"?>
<!--xslpupils.xml-->
<?xml-stylesheet type = "text/xsl" href = "xslpupils.xsl"?>
<pupils>
<pupil>
<id> student807 </id>
<lastname> Catlett </lastname>
<firstname> Herbert </firstname>
<classnumber> 55 </classnumber>
<email> herbert.catlett@firstdatacorp.com </email>
</pupil>

<pupil>
<id> student814 </id>
<lastname> Conti </lastname>
<firstname> Gilberto </firstname>
<classnumber> 55 </classnumber>
<email> gilberto.conti@firstdatacorp.com </email>
</pupil>

<pupil>
<id> student808 </id>
<lastname> Flekke </lastname>
<firstname> Curtis </firstname>
<classnumber> 55 </classnumber>
<email> cis-tap@flekke.com </email>
</pupil>

<pupil>
<id> student809 </id>
<lastname> Golla </lastname>
<firstname> Michael </firstname>
<classnumber> 55 </classnumber>
<email> michael.golla@firstdatacorp.com </email>
</pupil>

<pupil>
<id> student815</id>
<lastname> Grossoehme </lastname>
<firstname> Keith </firstname>
<classnumber> 55 </classnumber>
<email> keithcbk@cox.net </email>
</pupil>

<pupil>
<id> student817 </id>
<lastname> Guraedy </lastname>
<firstname> Phillip </firstname>
<classnumber> 55 </classnumber>
<email> phillip@guraedy.com </email>
</pupil>

<pupil>
<id> student813</id>
<lastname> Haugen </lastname>
<firstname> Melissa </firstname>
<classnumber> 55 </classnumber>
<email> melissa.haugen@firstdatacorp.com </email>
</pupil>

<pupil>
<id> student826 </id>
<lastname> Kunz </lastname>
<firstname> Matthew </firstname>
<classnumber> 55 </classnumber>
<email> cpu_rx@hotmail.com </email>
</pupil>


<pupil>
<id> student811</id>
<lastname> Skeen </lastname>
<firstname> Angela </firstname>
<classnumber> 55 </classnumber>
<email> anne_skeen@yahoo.com </email>
</pupil>

<pupil>
<id> student812 </id>
<lastname> Vanderloo </lastname>
<firstname> Mark </firstname>
<classnumber> 55 </classnumber>
<email> mjvanderloo@yahoo.com </email>
</pupil>

<pupil>
<id> student819</id>
<lastname> Vanderveen </lastname>
<firstname> Ronald </firstname>
<classnumber> 55 </classnumber>
<email> ron.vanderveen@firstdatacorp.com </email>
</pupil>


<pupil>
<id> student818 </id>
<lastname> Vaughn </lastname>
<firstname> Barry </firstname>
<classnumber> 55 </classnumber>
<email> von7668@cox.net </email>
</pupil>

</pupils>






and here is the code for the stylesheet.

<?xml version="1.0" encoding="UTF-8"?>
<!--xslpupils.xsl-->
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns = "http://www.w3.org/1999/xhtml"> 

<!-- The template for the whole document (the pupils element) -->
<xsl:template match = "xslpupils">

<h2> Class Information </h2>
<head>
<title> Class List </title>
</head>


<table border="1">
	  <tr bgcolor="#black">
		<th>id</th>
		<th>lastname</th>
		 <th>firstname</th>
		 <th>classnumber</th>
		  <th>email</th>
	  </tr>

	  <!--Apply the following to all occurrence of the pupil element-->
	  <xsl:for-each select="pupils/pupil">
	  <tr>
		<td><xsl:value-of select="id"/></td>
		<td><xsl:value-of select="lastname"/></td>
		 <td><xsl:value-of select="firstname"/></td>
		 <td><xsl:value-of select="classnumber"/></td>
		 <td><xsl:value-of select="email"/></td>
	  </tr>
	  </xsl:for-each>
	</table>

	 </xsl:template>
</xsl:stylesheet>



Can anyone make any sort of suggestion on how this could work?

Thanks,
Scott

Is This A Good Question/Topic? 0
  • +

Replies To: XSL Style Sheet Help

#2 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5832
  • View blog
  • Posts: 12,685
  • Joined: 16-October 07

Re: XSL Style Sheet Help

Posted 16 November 2009 - 11:12 AM

You missed the root.

Comments in XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<!--xslpupils.xsl-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns = "http://www.w3.org/1999/xhtml"> 
	<!-- There must always be a match for the root or nothing happens -->
	<xsl:template match="/">
		<!-- make your html valid -->
		<html>
			<head><title> Class List </title></head>
			<body>
				<h2> Class Information </h2>
				<!--
					for-each is a crutch, try to avoid it
					<xsl:for-each select="pupils/pupil">
				-->
				<xsl:apply-templates select="pupils"/>
			</body>
		</html>
	</xsl:template>

	<xsl:template match="pupils">
		<table border="1">
			<tr bgcolor="#black"><th>id</th><th>lastname</th><th>firstname</th><th>classnumber</th><th>email</th></tr>
			<xsl:apply-templates />
		</table>
	</xsl:template>

	<xsl:template match="pupil">
		<tr>
			<td><xsl:value-of select="id"/></td>
			<td><xsl:value-of select="lastname"/></td>
			<td><xsl:value-of select="firstname"/></td>
			<td><xsl:value-of select="classnumber"/></td>
			<td><xsl:value-of select="email"/></td>
		</tr>
	</xsl:template>
</xsl:stylesheet>



edit: tabs looked bad.

This post has been edited by baavgai: 16 November 2009 - 11:14 AM

Was This Post Helpful? 0
  • +
  • -

#3 BasementArtScott  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 49
  • Joined: 11-July 09

Re: XSL Style Sheet Help

Posted 16 November 2009 - 06:44 PM

View Postbaavgai, on 16 Nov, 2009 - 10:12 AM, said:

You missed the root.

Comments in XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<!--xslpupils.xsl-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns = "http://www.w3.org/1999/xhtml"> 
	<!-- There must always be a match for the root or nothing happens -->
	<xsl:template match="/">
		<!-- make your html valid -->
		<html>
			<head><title> Class List </title></head>
			<body>
				<h2> Class Information </h2>
				<!--
					for-each is a crutch, try to avoid it
					<xsl:for-each select="pupils/pupil">
				-->
				<xsl:apply-templates select="pupils"/>
			</body>
		</html>
	</xsl:template>

	<xsl:template match="pupils">
		<table border="1">
			<tr bgcolor="#black"><th>id</th><th>lastname</th><th>firstname</th><th>classnumber</th><th>email</th></tr>
			<xsl:apply-templates />
		</table>
	</xsl:template>

	<xsl:template match="pupil">
		<tr>
			<td><xsl:value-of select="id"/></td>
			<td><xsl:value-of select="lastname"/></td>
			<td><xsl:value-of select="firstname"/></td>
			<td><xsl:value-of select="classnumber"/></td>
			<td><xsl:value-of select="email"/></td>
		</tr>
	</xsl:template>
</xsl:stylesheet>



edit: tabs looked bad.



I still can't quite get it.

Here is my revised code.


<?xml version="1.0" encoding="UTF-8"?>
<!--xslpupils.xsl-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns = "http://www.w3.org/1999/xhtml"> 

	  
		<xsl:template match="pupil">
</xsl:template>
</xsl:stylesheet>


<!-- The template for the whole document (the pupils element) -->
<xsl:template match = "xslpupils">

<h2> Class Information </h2>
<html>
<head>
<title> Class List </title>
</head>


<table border="1">
	  <tr bgcolor="#black">
		<th>id</th>
		<th>lastname</th>
		 <th>firstname</th>
		 <th>classnumber</th>
		  <th>email</th>
	  </tr>
</table>
	  <!--Apply the following to all occurrence of the pupil element-->
	  <xsl:apply-templates select="pupil"/>

 </html>
		   </xsl:template>

		<xsl:template match="pupils">
				<table border="1">
				<tr bgcolor="#black"><th>id</th><th>lastname</th><th>firstname</th><th>classnumber</th><th>email</th></tr>
				<xsl:apply-templates />
				</table>
		</xsl:template>

		<xsl:template match="pupil">
				<tr>
						<td><xsl:value-of select="id"/></td>
						<td><xsl:value-of select="lastname"/></td>
						<td><xsl:value-of select="firstname"/></td>
						<td><xsl:value-of select="classnumber"/></td>
						<td><xsl:value-of select="email"/></td>
				</tr>
		</xsl:template>




I am currently getting this error

End tag 'xsl:stylesheet' does not match the start tag 'pupils'. Error processing resource 'file:///C:/Documents and Setting...

</xsl:stylesheet>


Can anyone suggest anything to get this working?

Thanks,
Scott
Was This Post Helpful? 0
  • +
  • -

#4 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5832
  • View blog
  • Posts: 12,685
  • Joined: 16-October 07

Re: XSL Style Sheet Help

Posted 16 November 2009 - 07:32 PM

The code I posted works. Ignore it if you like.

However, this is still non negotiable.
<!-- There must always be a match for the root or nothing happens -->
<xsl:template match="/">



If you don't have a match="/", nothing will happen; there's nowhere to start.
Was This Post Helpful? 0
  • +
  • -

#5 BasementArtScott  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 49
  • Joined: 11-July 09

Re: XSL Style Sheet Help

Posted 17 November 2009 - 05:56 AM

I am not ignoring you, I used the advice you gave me and added it to my code. I actually just went back and copied it verbatim, and this is the error I receive.

End tag 'xsl:stylesheet' does not match the start tag 'pupils'. Error processing resource 'file:///C:/Documents and Setting...

</xsl:stylesheet>
--^
Was This Post Helpful? 0
  • +
  • -

#6 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5832
  • View blog
  • Posts: 12,685
  • Joined: 16-October 07

Re: XSL Style Sheet Help

Posted 17 November 2009 - 08:06 AM

View PostBasementArtScott, on 17 Nov, 2009 - 06:56 AM, said:

</xsl:stylesheet>


Odd. Just just cut and pasted the posted code into an online validator ( http://validator.w3.org/ choose direct input and XHTML ). It is well formed XML, where the error you're getting is from an incomplete tag. Judging from the error, you have a "<pupils .." tag, which makes no sense.

When working with XSLT, or any XML based markup, the first step is well formed XML. Most web browsers will also highlight places where XML fails basic formating.
Was This Post Helpful? 0
  • +
  • -

#7 BasementArtScott  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 49
  • Joined: 11-July 09

Re: XSL Style Sheet Help

Posted 17 November 2009 - 01:39 PM

So what do you think I could do to make it work? I tried working with the line in question, but nothing I do seems to work.

Thanks for the help
-Scott
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1