2 Replies - 1719 Views - Last Post: 04 September 2013 - 11:05 AM

#1 MacJava  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 17-February 09

XSL document that transforms into XHTML

Post icon  Posted 08 October 2009 - 06:50 PM

I'm kind of confused about xsl and xml transformation subject.

This program supposed to display in the browser as a table and sort by the number of pages, rather than by chapter number, but whenever I tried to load it, all I see is the code. Am I missing something or my xsl is not well formatted. If you can help me. I will appreciated.


xml code


<?xml version = "1.0"?>
<?xml-stylesheet type = "text/xsl" href = "sorting_byPage.xsl"?>
 
<!-- Fig. 14.22 sorting.xml -->
<!-- XML document containing book information -->
<book isbn = "999-99999-9-X">
   <title>Deitel&apos;s XML Primer</title>
 
   <author>
	  <firstName>Jane</firstName>
	  <lastName>Blue</lastName>
   </author>
 
   <chapters>
	  <frontMatter>
		 <preface pages = "2" />
		 <contents pages = "5" />
		 <illustrations pages = "4" />
	  </frontMatter>
 
	  <chapter number = "3" pages = "44">Advanced XML</chapter>
	  <chapter number = "2" pages = "35">Intermediate XML</chapter>
	  <appendix number = "B" pages = "26">Parsers and Tools</appendix>
	  <appendix number = "A" pages = "7">Entities</appendix>
	  <chapter number = "1" pages = "28">XML Fundamentals</chapter>
   </chapters>
 
   <media type = "CD" />
</book>
 



xsl code


<?xml version="1.0"?> 
 
 <!--  Fig. 14.23: sorting_byPage.xsl --> 
 <!--  Transformation of book information into XHTML --> 
 <xsl:stylesheet version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 
 
 <!--  write XML declaration and DOCTYPE DTD information --> 
  <xsl:output method="html" omit-xml-declaration="no" 
  doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" 
  doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" /> 
 
 
 <!--  match document root --> 
 <xsl:template match="/">
	<html xmlns="http://www.w3.org/1999/xhtml">
		<xsl:apply-templates /> 
	</html>
  </xsl:template>
 
 
 <!--  match book --> 
 <xsl:template match="book">
	 <head>
		<title>ISBN <xsl:value-of select="@isbn" /> - 
			<xsl:value-of select="title" /> 
		</title>
	 </head>
	 <body>
		  <h1 style="color: blue"><xsl:value-of select="title" /></h1>
		  <h2 style="color: blue">by 
			  <xsl:value-of select="author/lastName" />, 
			  <xsl:value-of select="author/firstName" /></h2>
 
 
		 <table style="border-style: groove; background-color: wheat">
 
			<xsl:for-each select="chapters/frontMatter/*">
			   <tr>
				  <td style="text-align: right">
					 <xsl:value-of select="name()" /> 
				  </td>
				<td>
				   ( <xsl:value-of select="@pages" /> pages ) 
				</td>
			   </tr>
  </xsl:for-each>
 
 
	  <xsl:for-each select="chapters/chapter">
		 <xsl:sort select="@pages" data-type="number" order="descending" /> 
	  <tr>
		 <td style="text-align: right">
			 Chapter <xsl:value-of select="@number" /> 
		 </td>
 
 
		 <td>
			<xsl:value-of select="text()" /> 
			 ( <xsl:value-of select="@pages" /> pages ) 
		</td>
	  </tr>
  </xsl:for-each>
 
  <xsl:for-each select="chapters/appendix">
	 <xsl:sort select="@number" data-type="text" order="ascending" /> 
   <tr>
	   <td style="text-align: right">
		  Appendix <xsl:value-of select="@number" /> 
	   </td>
 
 
	   <td>
		 <xsl:value-of select="text()" /> 
		  ( <xsl:value-of select="@pages" /> pages ) 
	  </td>
  </tr>
 </xsl:for-each>
</table>
 
 
  <br /> <p style="color: blue">Pages: 
	  <xsl:variable name="pagecount" 
		 select="sum(chapters//*/@pages)" /> 
	  <xsl:value-of select="$pagecount" /> 
	<br />Media Type: <xsl:value-of select="media/@type" /></p>
   </body>
 </xsl:template>
</xsl:stylesheet>




Is This A Good Question/Topic? 0
  • +

Replies To: XSL document that transforms into XHTML

#2 thehat  Icon User is offline

  • awake ? web();
  • member icon

Reputation: 106
  • View blog
  • Posts: 951
  • Joined: 28-February 08

Re: XSL document that transforms into XHTML

Posted 09 October 2009 - 06:01 AM

Your code seems to displaying as intended for me in FireFox 3 and IE7.
Posted Image
Which file are you attempting to view, and what browser are you using?
Was This Post Helpful? 0
  • +
  • -

#3 ncis_sg1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 04-May 12

Re: XSL document that transforms into XHTML

Posted 04 September 2013 - 11:05 AM

I am also having the same issue I know this is an old topic but I did not want to start a new one because it is basically the same code just being sorted with an XSLT modification. I have all the code but I do not know how to render it in my browser. How do I get my image to appear and not my code?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1