DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2011
    Posts
    1

    Help with my homework

    I've been working on my homework assignment for a while now and it's been giving me fits. I'll start with step 3:

    step3 says: below the output element, create a global variable named redcell that contains the following result tree fragment. (I'm not sure if I did this right)

    Step 4 says: go to the candidate template, and create a variable named percent that is equal to the value of the votes element divided by the sum of the votes for all the candidates in the race.(Hint: the location path for all the votes for the current race is "..//votes".)

    Here is my code:
    Code:
    <xsl:stylesheet version='1.0' xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" version="4.0" />
    
    <xsl:variable name="redcell">
    	<td>
    		<xsl:value-of select="@red" />
    	</td>
    </xsl:variable>
    
    <xsl:variable name="bluecell">
    	<td>
    		<xsl:value-of select="@blue" />
    	</td>
    </xsl:variable>
    
    <xsl:variable name="greencell">
    	<td>
    		<xsl:value-of select="@green" />
    	</td>
    </xsl:variable>
    
    
    <xsl:template match="/">
       <html>
       <head>
          <title>Election Night Results</title>
          <link href="polls.css" rel="stylesheet" type="text/css" />
       </head>
       <body>
          <div id="intro">
             <p><img src="logo.jpg" alt="Election Day Results" /></p>
             <a href="#">Election Home Page</a>
             <a href="#">President</a>
             <a href="#">Senate Races</a>
             <a href="#">Congressional Races</a>
             <a href="#">State Senate</a>
             <a href="#">State House</a>
             <a href="#">Local Races</a>
             <a href="#">Judicial</a>
             <a href="#">Referendums</a>
          </div>
    
          <div id="results">
             <h1>Congressional Races</h1>
             <xsl:apply-templates select="polls/race" />
          </div>
       </body>
       </html>
    </xsl:template>
    
    <xsl:template match="race">
       <h2><xsl:value-of select="title" /></h2>
       <table cellpadding="1" cellspacing="1">
          <tr><th>Candidate</th><th class="num">Votes</th></tr>
          <xsl:apply-templates select="candidate" />
       </table>
    </xsl:template>
    
    <xsl:template match="candidate">
    	<xsl:variable name="percent">
    		<td><xsl:value-of select="@votes div (..//@votes)" /> </td>
    	</xsl:variable>
       <tr>
          <td class="name"><xsl:value-of select="name" /> (<xsl:value-of select="party" />)</td>
          <td class="num"><xsl:value-of select="format-number(votes, '#,##0')" /></td>
       </tr>
    </xsl:template>
    
    <xsl:template match="showBar">
    	<xsl:param name="cells" select="0" />
    	<xsl:param name="partyType" />
    	
    	<xsl:if test="$cell[position() > 0]" />
    </xsl:template>
    
    </xsl:stylesheet>

  2. #2
    Join Date
    Apr 2011
    Posts
    1
    Here is the xml file if that helps;
    Code:
    <?xml-stylesheet type="text/xsl" href="polls.xsl" ?>
    
    <polls>
       <race>
          <title>1st Congressional District</title>
          <candidate>
             <name>Sarah Carlson</name>
             <party>D</party>
             <votes>45125</votes>
          </candidate>
          <candidate>
             <name>Pete deJesus</name>
             <party>R</party>
             <votes>44498</votes>
          </candidate>
          <candidate>
             <name>Alan Tompkins</name>
             <party>I</party>
             <votes>5143</votes>
          </candidate>
       </race>
       <race>
          <title>2nd Congressional District</title>
          <candidate>
             <name>Gary Griffin</name>
             <party>D</party>
             <votes>69505</votes>
          </candidate>
          <candidate>
             <name>Frank Brown</name>
             <party>R</party>
             <votes>78133</votes>
          </candidate>
          <candidate>
             <name>Roland Washington</name>
             <party>G</party>
             <votes>8109</votes>
          </candidate>
          <candidate>
             <name>Karen Reese</name>
             <party>L</party>
             <votes>13004</votes>
          </candidate>
       </race>
       <race>
          <title>3rd Congressional District</title>
          <candidate>
             <name>Anne Sanchez</name>
             <party>D</party>
             <votes>65203</votes>
          </candidate>
          <candidate>
             <name>Cynthia Thomas</name>
             <party>R</party>
             <votes>51289</votes>
          </candidate>
       </race>
       <race>
          <title>4th Congressional District</title>
          <candidate>
             <name>Jerry Wilkes</name>
             <party>D</party>
             <votes>49201</votes>
          </candidate>
          <candidate>
             <name>Barry Mitchell</name>
             <party>R</party>
             <votes>58414</votes>
          </candidate>
          <candidate>
             <name>Paula Wellton</name>
             <party>I</party>
             <votes>3901</votes>
          </candidate>
       </race>
       <race>
          <title>5th Congressional District</title>
          <candidate>
             <name>Pete Grimbold</name>
             <party>D</party>
             <votes>42105</votes>
          </candidate>
          <candidate>
             <name>Carol Ives</name>
             <party>R</party>
             <votes>43349</votes>
          </candidate>
          <candidate>
             <name>Michael Dorn</name>
             <party>G</party>
             <votes>1401</votes>
          </candidate>
       </race>
    </polls>

  3. #3
    Join Date
    May 2009
    Posts
    60
    I still fits anchor to the individual election districts
    let's
    with a template I can not do anything because there is no attribute are to be found to this xml file
    Code:
    <xsl:variable name="redcell">
    	<td>
    		<xsl:value-of select="@red" />
    	</td>
    </xsl:variable>
    <xsl:variable name="bluecell">
    	<td>
    		<xsl:value-of select="@blue" />
    	</td>
    </xsl:variable>
    Code:
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    	<xsl:output method="html" indent="yes" doctype-public="-//W3C//DTD HTML 4.0 Transitional//EN" doctype-system="_http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>
    <xsl:template match="/">
    		<html>
    			<style title="text/css">table {
    border: 2px solid black;
    width:60%
    }
    th,td{
    border: 2px solid black;
    }
    tr{
    text-align: right;
    }
    tr.head{
    background-color:#ff0000;
    }
    tr.tot{
    background-color:#0000ff;
    }
    tr.odd{
    background-color:#ff9900;
    }
    tr.even{
    background-color:#ff0099;
    }
    .num{
    width:30%
    }
    .pro{
    width:30%
    }</style>
    			<head>
    				<title>Election Night Results</title>
    			</head>
    			<body>
    			<a name="top"></a>
    				<div id="intro">
    					<p>
    						<img src="logo.jpg" alt="Election Day Results"/>
    					</p>
    					<a href="#">Election Home Page</a>
    					<a href="#">President</a>
    					<a href="#">Senate Races</a>
    					<a href="#">Congressional Races</a>
    					<a href="#">State Senate</a>
    					<a href="#">State House</a>
    					<a href="#">Local Races</a>
    					<a href="#">Judicial</a>
    					<a href="#">Referendums</a>
    				</div>
    				<div id="results">
    					<h1>Congressional Races</h1>
    					<xsl:apply-templates select="polls/race" mode="href"/>
    					<xsl:apply-templates select="polls/race"/>
    				</div>
    			</body>
    		</html>
    	</xsl:template>
    	<xsl:template match="race">
    		<xsl:variable name="sum" select="sum(.//votes)"/>
    		<h2>
    			<a name="{title}">
    				<xsl:value-of select="title"/>
    			</a>
    			<a href="#top">    Top</a>
    		</h2>
    		<table cellpadding="1" cellspacing="1">
    			<tr class="head">
    				<th>Candidate</th>
    				<th class="num">Votes</th>
    				<th class="pos">Procent</th>
    			</tr>
    			<xsl:apply-templates select="candidate">
    				<xsl:with-param name="sum" select="$sum"/>
    			</xsl:apply-templates>
    			<tr class="tot">
    				<td>total</td>
    				<td>
    					<xsl:value-of select="$sum"/>
    				</td>
    				<td>&#xA0;</td>
    			</tr>
    		</table>
    	</xsl:template>
    	<xsl:template match="candidate">
    		<xsl:param name="sum"/>
    		<tr>
    			<xsl:attribute name="class">
    				<xsl:choose>
    					<xsl:when test="position() mod 2 =0">
    						<xsl:text>even</xsl:text>
    					</xsl:when>
    					<xsl:otherwise>
    						<xsl:text>odd</xsl:text>
    					</xsl:otherwise>
    				</xsl:choose>
    			</xsl:attribute>
    			<td class="name">
    				<xsl:value-of select="name"/>(<xsl:value-of select="party"/>)</td>
    			<td class="num">
    				<xsl:value-of select="format-number(votes, '#,##0')"/>
    			</td>
    			<td class="pro">
    				<xsl:value-of select="format-number(votes div $sum, '#0.000%')"/>
    			</td>
    		</tr>
    	</xsl:template>
    	<xsl:template match="race" mode="href">
    		<p>
    			<a href="#{title}">
    				goto <xsl:value-of select="title"/>
    			</a>
    		</p>
    	</xsl:template>
    </xsl:stylesheet>
    result
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "_http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
      <style title="text/css">table {
    border: 2px solid black;
    width:60%
    }
    th,td{
    border: 2px solid black;
    }
    tr{
    text-align: right;
    }
    tr.head{
    background-color:#ff0000;
    }
    tr.tot{
    background-color:#0000ff;
    
    }
    tr.odd{
    background-color:#ff9900;
    }
    tr.even{
    background-color:#ff0099;
    }
    .num{
    width:30%
    }
    .pro{
    width:30%
    }
      </style>
      <head>
        <meta http-equiv="Content-Type" content="text/html">
        <title>Election Night Results</title>
      </head>
      <body>
        <a name="top"></a>
        <div id="intro">
          <p>
            <img src="logo.jpg" alt="Election Day Results">
          </p>
          <a href="#">Election Home Page</a>
          <a href="#">President</a>
          <a href="#">Senate Races</a>
          <a href="#">Congressional Races</a>
          <a href="#">State Senate</a>
          <a href="#">State House</a>
          <a href="#">Local Races</a>
          <a href="#">Judicial</a>
          <a href="#">Referendums</a>
        </div>
        <div id="results">
          <h1>Congressional Races</h1>
          <p>
            <a href="#1st Congressional District">
    				goto 1st Congressional District
            </a>
          </p>
          <p>
            <a href="#2nd Congressional District">
    				goto 2nd Congressional District
            </a>
          </p>
          <p>
            <a href="#3rd Congressional District">
    				goto 3rd Congressional District
            </a>
          </p>
          <p>
            <a href="#4th Congressional District">
    				goto 4th Congressional District
            </a>
          </p>
          <p>
            <a href="#5th Congressional District">
    				goto 5th Congressional District
            </a>
          </p>
          <h2>
            <a name="1st Congressional District">1st Congressional District</a>
            <a href="#top">    Top</a>
          </h2>
          <table cellpadding="1" cellspacing="1">
            <tr class="head">
              <th>Candidate</th>
              <th class="num">Votes</th>
              <th class="pos">Procent</th>
            </tr>
            <tr class="odd">
              <td class="name">Sarah Carlson(D)</td>
              <td class="num">45,125</td>
              <td class="pro">47.617%</td>
            </tr>
            <tr class="even">
              <td class="name">Pete deJesus(R)</td>
              <td class="num">44,498</td>
              <td class="pro">46.956%</td>
            </tr>
            <tr class="odd">
              <td class="name">Alan Tompkins(I)</td>
              <td class="num">5,143</td>
              <td class="pro">5.427%</td>
            </tr>
            <tr class="tot">
              <td>total</td>
              <td>94766</td>
              <td>&nbsp;</td>
            </tr>
          </table>
          <h2>
            <a name="2nd Congressional District">2nd Congressional District</a>
            <a href="#top">    Top</a>
          </h2>
          <table cellpadding="1" cellspacing="1">
            <tr class="head">
              <th>Candidate</th>
              <th class="num">Votes</th>
              <th class="pos">Procent</th>
            </tr>
            <tr class="odd">
              <td class="name">Gary Griffin(D)</td>
              <td class="num">69,505</td>
              <td class="pro">41.188%</td>
            </tr>
            <tr class="even">
              <td class="name">Frank Brown(R)</td>
              <td class="num">78,133</td>
              <td class="pro">46.301%</td>
            </tr>
            <tr class="odd">
              <td class="name">Roland Washington(G)</td>
              <td class="num">8,109</td>
              <td class="pro">4.805%</td>
            </tr>
            <tr class="even">
              <td class="name">Karen Reese(L)</td>
              <td class="num">13,004</td>
              <td class="pro">7.706%</td>
            </tr>
            <tr class="tot">
              <td>total</td>
              <td>168751</td>
              <td>&nbsp;</td>
            </tr>
          </table>
          <h2>
            <a name="3rd Congressional District">3rd Congressional District</a>
            <a href="#top">    Top</a>
          </h2>
          <table cellpadding="1" cellspacing="1">
            <tr class="head">
              <th>Candidate</th>
              <th class="num">Votes</th>
              <th class="pos">Procent</th>
            </tr>
            <tr class="odd">
              <td class="name">Anne Sanchez(D)</td>
              <td class="num">65,203</td>
              <td class="pro">55.972%</td>
            </tr>
            <tr class="even">
              <td class="name">Cynthia Thomas(R)</td>
              <td class="num">51,289</td>
              <td class="pro">44.028%</td>
            </tr>
            <tr class="tot">
              <td>total</td>
              <td>116492</td>
              <td>&nbsp;</td>
            </tr>
          </table>
          <h2>
            <a name="4th Congressional District">4th Congressional District</a>
            <a href="#top">    Top</a>
          </h2>
          <table cellpadding="1" cellspacing="1">
            <tr class="head">
              <th>Candidate</th>
              <th class="num">Votes</th>
              <th class="pos">Procent</th>
            </tr>
            <tr class="odd">
              <td class="name">Jerry Wilkes(D)</td>
              <td class="num">49,201</td>
              <td class="pro">44.120%</td>
            </tr>
            <tr class="even">
              <td class="name">Barry Mitchell(R)</td>
              <td class="num">58,414</td>
              <td class="pro">52.382%</td>
            </tr>
            <tr class="odd">
              <td class="name">Paula Wellton(I)</td>
              <td class="num">3,901</td>
              <td class="pro">3.498%</td>
            </tr>
            <tr class="tot">
              <td>total</td>
              <td>111516</td>
              <td>&nbsp;</td>
            </tr>
          </table>
          <h2>
            <a name="5th Congressional District">5th Congressional District</a>
            <a href="#top">    Top</a>
          </h2>
          <table cellpadding="1" cellspacing="1">
            <tr class="head">
              <th>Candidate</th>
              <th class="num">Votes</th>
              <th class="pos">Procent</th>
            </tr>
            <tr class="odd">
              <td class="name">Pete Grimbold(D)</td>
              <td class="num">42,105</td>
              <td class="pro">48.477%</td>
            </tr>
            <tr class="even">
              <td class="name">Carol Ives(R)</td>
              <td class="num">43,349</td>
              <td class="pro">49.910%</td>
            </tr>
            <tr class="odd">
              <td class="name">Michael Dorn(G)</td>
              <td class="num">1,401</td>
              <td class="pro">1.613%</td>
            </tr>
            <tr class="tot">
              <td>total</td>
              <td>86855</td>
              <td>&nbsp;</td>
            </tr>
          </table>
        </div>
      </body>
    </html>

Similar Threads

  1. Replies: 2
    Last Post: 11-08-2010, 11:36 AM
  2. VB.net Homework project
    By firedwg1 in forum .NET
    Replies: 5
    Last Post: 06-29-2006, 01:54 AM
  3. java homework
    By Mona in forum Java
    Replies: 6
    Last Post: 06-22-2006, 02:54 AM
  4. Replies: 2
    Last Post: 05-11-2006, 01:29 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links