Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Using XML with CSS and XSL - help

    So I'm trying to get this xml document to read the xsl document and format itself to a table created by the xsl. However, the xml isn't using the data that's in the xsl code and is coming up almost entirely blank when I put it through my browser. Here is the xls code:


    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:key name="movies" match="poll" use="." />
    <xsl:variable name="single-movie" select="//movie[generate-id(.) = generate-id(key('movies', .))]/."/>
    	<xsl:template match="/">
    		<html>
    			<head>
    				<title>Top American Comedies</title>
    				<link href="comedy.css" rel="stylesheet" type="text/css"/>
    			</head>
    			<body>
    				<h2>The Top American Comedy Films</h2>
    				<p>Number of Ballots: <xsl:value-of select="count(poll/ballot)"/></p>
    				<table>
    					<tr>
    						<th>Rank</th>
    						<th>Movie</th>
    						<th>Votes</th>
    						<th>%</th>
    					</tr>
    <xsl:for-each select="$single-movie">
    <xsl:sort select="count(key('movies', current()))" data-type="number" order="descending"/>
    <xsl:variable name="votes" select="count(key('movies', current()))"/>
    <tr>
    <td>
    <xsl:value-of select="position()"/>
    	  		 				  		.
    	  		 				  	</td>
    	  		 				  	<td>
    	  		 				  	<xsl:value-of select="movie"/>
    	  		 				  	</td>
    	  		 				  	<td align="right">
    	  		 				  	<xsl:value-of select="$votes"/>
    	  		 				  	</td>
    	  		 				  	<td align="right">
    	  		 				  	<xsl:value-of select="format-number($votes div count(//ballot), '#.00%')"/>
    	  		 				  	</td>
    	  		 				  	</tr>
    	  		 				  	<xsl:if test="position() mod 10 = 0">
    	  		 				  	<tr>
    	  		 				  	<td colspan="4">
    	  		 				  	
    	  		 				  	</td>
    	  		 				  	</tr>
    	  		 				  	</xsl:if>
    	  		 				  	</xsl:for-each>
    	  		 				  	</table>
    			</body>
    		</html>
    	</xsl:template>
    </xsl:stylesheet>
    Thanks for any help you can give

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,081
    Thanks
    23
    Thanked 592 Times in 591 Posts
    What you have posted uniquelydrew is an XSL style sheet for a xml file. It is not a xml file as you stated. You have to get the xml file and link that file to this stylesheet.

    In the xml file just under this line:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    Put this line:
    <?xml-stylesheet type="text/xsl" href="WRITE THE XSL FILE NAME HERE"?>

  • #3
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Problem with the xsl, not the xml

    I'm pretty sure I linked in the XSL file to the XML properly. The problem that I'm encountering is that the data in the XML file isn't displaying when I run it through my browser. It will only show the basic table and header created by the XSL file without filling it in using the XML

  • #4
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,081
    Thanks
    23
    Thanked 592 Times in 591 Posts
    Could you please post the xml file(best) or a part of it or a place where we can get it.

  • #5
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    <?xml version="1.0" encoding="UTF-8" ?>
    <!--
       New Perspectives on XML
       Tutorial 8
       Case Problem 1
    
       Best American Comedies
       Author: 
       Date: 
    
       Filename:         comedy.xml
       Supporting Files: comedy.xsl
    -->
    <?xml-stylesheet type="text/xsl" href="comedy.xsl" ?> 
    <poll>
    <ballot id="b1">
       <movie>A FISH CALLED WANDA (1988)</movie>
       <movie>ADAM'S RIB (1949)</movie>
       <movie>ANNIE HALL (1977)</movie>
       <movie>BEING THERE (1979)</movie>
       <movie>BORN YESTERDAY (1950)</movie>
       <movie>CITY LIGHTS (1931)</movie>
       <movie>DR. STRANGELOVE (1964)</movie>
       <movie>GOOD MORNING, VIETNAM (1987)</movie>
       <movie>HIS GIRL FRIDAY (1940)</movie>
       <movie>M*A*S*H (1970)</movie>
       <movie>MOONSTRUCK (1987)</movie>
       <movie>NATIONAL LAMPOON'S ANIMAL HOUSE (1978)</movie>
       <movie>SILVER STREAK (1976)</movie>
       <movie>SOME LIKE IT HOT (1959)</movie>
       <movie>THE GENERAL (1927)</movie>
       <movie>THE GRADUATE (1967)</movie>
       <movie>THE ODD COUPLE (1968)</movie>
       <movie>THE SEVEN YEAR ITCH (1955)</movie>
       <movie>TO BE OR NOT TO BE (1942)</movie>
       <movie>WHAT'S UP, DOC? (1972)</movie>
    </ballot>
    There are a total of 162 ballots so I'll skip to the closing tags

    Code:
    <ballot id="b162">
       <movie>A DAY AT THE RACES (1937)</movie>
       <movie>ABBOTT AND COSTELLO MEET FRANKENSTEIN (1948)</movie>
       <movie>AMERICAN GRAFFITI (1973)</movie>
       <movie>BANANAS (1971)</movie>
       <movie>BLAZING SADDLES (1974)</movie>
       <movie>CADDYSHACK (1980)</movie>
       <movie>DR. STRANGELOVE (1964)</movie>
       <movie>GHOSTBUSTERS (1984)</movie>
       <movie>HIS GIRL FRIDAY (1940)</movie>
       <movie>IT'S A MAD MAD MAD MAD WORLD (1963)</movie>
       <movie>MODERN TIMES (1936)</movie>
       <movie>NATIONAL LAMPOON'S ANIMAL HOUSE (1978)</movie>
       <movie>SHE DONE HIM WRONG (1933)</movie>
       <movie>SOME LIKE IT HOT (1959)</movie>
       <movie>THE AWFUL TRUTH (1937)</movie>
       <movie>THE GRADUATE (1967)</movie>
       <movie>THE ODD COUPLE (1968)</movie>
       <movie>THE PRODUCERS (1968)</movie>
       <movie>THIS IS SPINAL TAP (1984)</movie>
       <movie>TOPPER (1937)</movie>
    </ballot>
    </poll>

  • #6
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,081
    Thanks
    23
    Thanked 592 Times in 591 Posts
    Your style sheet is trying to show variables that are not in the xml. Only <movie> is in the xml.
    I also think it is trying to calculate the number one movie, and the number 2, 3, etc.. Not sure xsl or myself can do that.

    If we take out the variables that are not in xml we get this:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:key name="movies" match="poll" use="." />
    <xsl:variable name="single-movie" select="//movie[generate-id(.) = generate-id(key('movies', .))]/."/>
    <xsl:template match="/">
    	<html>
    	<head>
    	<title>Top American Comedies</title>
    	<link href="comedy.css" rel="stylesheet" type="text/css"/>
    	</head>
    	<body>
    	<h2>The Top American Comedy Films</h2>
    	<p>Number of Ballots: <xsl:value-of select="count(poll/ballot/movie)"/></p>
    
    	<table border="1">
    		<tr>
    			<th>Rank</th>
    			<th>Movie</th>
    			<th>Votes</th>
    			<th>%</th>
    		</tr>
    		<xsl:for-each select="poll/ballot">
    		<tr>
    			<td>1</td>
    			<td>
    			<xsl:value-of select="movie"/>
    			</td>
    			<td>3</td>
    			<td>4</td>
    		</tr>
    		</xsl:for-each>
    	</table>
    	</body>
    	</html>
    </xsl:template>
    </xsl:stylesheet>
    It does show the first vote of all 162 ballots. And that is what it is suppose to do. Maybe we should look at this a little more and see if can get this working.
    Last edited by sunfighter; 03-07-2013 at 04:24 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •