0

作业完成。我通过反复试验弄清楚了一切。只有一件事困扰着我。在位于公司名称下方的每个表格下方,表格下方和下一个公司名称之前没有空格。它看起来很俗气。想在每张桌子下面加一个空格。有任何想法吗?

我正在研究一个使用 XML 和 XSLT 的项目,并且已经完成了相当多的工作。剩下的就是将描述文本放在表格的右侧,并用适当的信息填充表格的第二列。

我已经为描述性文本尝试了 float:right、text-align:right 和 align:right,但它不会移动到表格的右侧。关于如何做到这一点的任何想法?

此外,我需要在每一行的表格的第二列中填写一些与该公司直接相关的信息。我了解如何使用数据来填充表格,但这些信息不是数据。例如,表中的第一行和第一列是“类别”。我将“类别”一词硬编码到第一列。对于该行的第二列,我需要显示正确的类别类型,如“工业”,但“工业”这个词不是数据 - 它的设置如下:工业。我已将信息的去向留空。

这是我的网站的链接:

这是我的代码:

XML

<?xml version="1.0" encoding="UTF-8" ?>

<?xml-stylesheet type="text/xsl" href="stock2.xsl"?>

<portfolio>

<author>Kevin Summers</author>
<date>11/24/2008</date>
<time>14:54</time>

<stock>
  <sName symbol="AA">Aluminum Company of America</sName>
  <description>Alcoa Inc. is a producer of primary aluminum, fabricated aluminum, and 
               alumina, and is active in all major aspects of the industry, including 
               technology, mining, refining, smelting, fabricating, and recycling. 
               Alcoa serves customers worldwide in the packaging, consumer, automotive, 
               aerospace and other transportation, building and construction, industrial 
               products and distribution markets. Related businesses include packaging 
               machinery, precision castings, vinyl siding, plastic bottles and closures, 
               fiber-optic cables, and electrical distribution systems for cars and 
               trucks. Alcoa's operations consist of five worldwide segments: Alumina 
               and Chemicals, Primary Metals, Flat-Rolled Products, Engineered Products, 
               and Packaging and Consumer Goods.
  </description>
  <category>Industrials</category>
  <link>http://www.alcoa.com</link>
  <year_high>42.00</year_high>
  <year_low>27.36</year_low>
  <pe_ratio>39.40</pe_ratio>
  <earnings>0.73</earnings>
  <yield>2.09</yield>
  <today open="29.60" high="29.94" low="28.59" current="29.20" vol="2.94" />
</stock>

<stock>
  <sName symbol="UCL">Unocal Corporation</sName>
  <description>Unocal Corporation operates as the parent of Union Oil Company of 
               California. Virtually all operations are conducted by Union Oil and 
               its subsidiaries. Unocal is an independent oil and gas exploration 
               and production company, with principal operations in North America 
               and Asia. Unocal is also a producer of geothermal energy and a provider 
               of electrical power in Asia. Other activities include ownership in 
               proprietary and common carrier pipelines, natural gas storage facilities 
               and the marketing and trading of hydrocarbon commodities.
  </description>
  <category>Industrials</category>
  <link>http://www.unocal.com</link>
  <year_high>39.70</year_high>
  <year_low>29.51</year_low>
  <pe_ratio>24.57</pe_ratio>
  <earnings>1.34</earnings>
  <yield>2.43</yield>
  <today open="33.35" high="34.00" low="32.66" current="33.80" vol="1.01" />
</stock>

<stock>
  <sName symbol="GM">General Motors Corporation</sName>
  <description>General Motors Corp. is a diversified automotive business with 
               additional interests in communications services, locomotives, finance 
               and insurance. GM's automotive business designs, manufactures, and/or 
               markets vehicles primarily in North America under the Chevrolet, Pontiac, 
               GMC, Oldsmobile, Buick, Cadillac, Saturn and Hummer nameplates, and 
               outside North America under the Opel, Vauxhall, Holden, Isuzu, Saab, 
               Buick, Chevrolet, GMC and Cadillac nameplates. GM's communications 
               services relate to its Hughes Electronics Corporation subsidiary, 
               which includes digital entertainment, information and communications 
               services, and satellite-based private business networks. GM also is 
               engaged in the design, manufacturing and marketing of locomotives and 
               heavy-duty transmissions. GM's financing and insurance operations are 
               conducted primarily through General Motors Acceptance Corporation, which 
               provides a broad range of financial services.
  </description>
  <category>Industrials</category>
  <link>http://www.gm.com</link>
  <year_high>68.17</year_high>
  <year_low>39.17</year_low>
  <pe_ratio>11.29</pe_ratio>
  <earnings>4.06</earnings>
  <yield>4.36</yield>
  <today open="46.67" high="47.00" low="44.53" current="46.67" vol="6.08" />
</stock>

<stock>
  <sName symbol="EK">Eastman Kodak Company</sName>
  <description>Eastman Kodak Company (Kodak) is engaged primarily in developing, 
               manufacturing and marketing traditional and digital imaging products, 
               services and solutions for consumers, professionals, healthcare 
               providers, the entertainment industry and other commercial customers. 
               The Company is a major participant in the "infoimaging" industry, 
               which is composed of devices (digital cameras and personal data 
               assistants), infrastructure (online networks and delivery systems for 
               images) and services and media (software, film and paper enabling 
               people to access, analyze and print images). Kodak uses its technology, 
               market reach and a host of industry partnerships to provide products 
               and services for customers that need the information-rich content that 
               images contain.
  </description>
  <category>Industrials</category>
  <link>http://www.kodak.com</link>
  <year_high>47.30</year_high>
  <year_low>24.40</year_low>
  <pe_ratio>na</pe_ratio>
  <earnings>-0.13</earnings>
  <yield>6.29</yield>
  <today open="29.40" high="29.84" low="27.83" current="29.84" vol="3.16" />
</stock>

<stock>
  <sName symbol="R">Ryder Systems Incorporated</sName>
  <description>Ryder System, Inc. is a provider of logistics, supply chain and 
               transportation management solutions worldwide. The Company operates 
               in three reportable business segments: Fleet Management Solutions, 
               which provides full-service leasing, commercial rental and programmed 
               maintenance of trucks, tractors and trailers to customers, principally 
               in the United States, Canada and the United Kingdom; Supply Chain 
               Solutions, which provides comprehensive supply chain consulting and 
               lead logistics management solutions that support customers' entire 
               supply chains, from inbound raw materials through distribution of 
               finished goods throughout North America, in Latin America, Europe and 
               Asia, and Dedicated Contract Carriage, which provides vehicles and 
               drivers as part of a dedicated transportation solution, principally 
               in North America. 
  </description>
  <category>Transportation</category>
  <link>http://www.ryder.com</link>
  <year_high>31.09</year_high>
  <year_low>17.02</year_low>
  <pe_ratio>13.79</pe_ratio>
  <earnings>1.85</earnings>
  <yield>2.35</yield>
  <today open="25.62" high="26.29" low="24.93" current="25.23" vol="0.26" />
</stock>

<stock>
  <sName symbol="ABF">Airborne Freight Corporation</sName>
  <description>Airborne Freight Corporation is an air express company and air freight 
               forwarder that expedites shipments of all sizes to destinations 
               throughout the United States and most foreign countries. ABX Air, Inc., 
               the Company's principal wholly owned subsidiary, provides domestic 
               express cargo service and cargo service to Canada. The Company is the 
               sole customer of ABX for this service. ABX also offers limited charter 
               service. Airborne Express provides door-to-door express delivery of 
               small packages and documents throughout the United States and to and 
               from most foreign countries. The Company also acts as an international 
               and domestic freight forwarder for shipments of any size.
  </description>
  <category>Transportation</category>
  <link>http://www.airborne.com</link>
  <year_high>23.34</year_high>
  <year_low>7.00</year_low>
  <pe_ratio>207.67</pe_ratio>
  <earnings>0.06</earnings>
  <yield>1.28</yield>
  <today open="12.80" high="13.18" low="11.90" current="13.00" vol="1.00" />
</stock>

<stock>
  <sName symbol="LUV">Southwest Airlines Corporation</sName>
  <description>Southwest Airlines Co. is a domestic airline that provides primarily 
               short-haul, high-frequency, point-to-point, low-fare service. Southwest 
               focuses principally on point-to-point, rather than hub-and-spoke service 
               in markets with frequent, conveniently timed flights and low fares. 
               The Company serves many conveniently located satellite or downtown 
               airports such as Dallas Love Field, Houston Hobby, Chicago Midway, 
               Baltimore-Washington International, Burbank, Manchester, Oakland, 
               San Jose, Providence, Ft. Lauderdale/Hollywood and Long Island airports, 
               which are typically less congested than other airlines' hub airports.
  </description>
  <category>Transportation</category>
  <link>http://www.southwest.com</link>
  <year_high>22.00</year_high>
  <year_low>11.25</year_low>
  <pe_ratio>25.46</pe_ratio>
  <earnings>0.54</earnings>
  <yield>0.07</yield>
  <today open="14.00" high="14.59" low="13.53" current="14.00" vol="4.03" />
</stock>

<stock>
  <sName symbol="CNI">Canadian National Railway Corporation</sName>
  <description>Canadian National Railway is the only rail network on the continent 
               to connect three coasts: the Pacific, the Atlantic and the Gulf of 
               Mexico. The Company derives revenue from seven business units. The 
               Petroleum and Chemicals unit transports a wide range of commodities, 
               including chemicals, plastics, petroleum and gas products. The Metals 
               and Minerals unit primarily transports nonferrous base metals, steel, 
               equipment and parts. The Forest Products unit transports various types 
               of lumber, panels, wood chips, wood pulp, pulpwood, printing paper, 
               linerboard and newsprint. The Coal unit transports thermal and 
               metallurgical grades of coal. The Grain and Fertilizer primarily 
               transports commodities grown in western Canada and the United States 
               Midwest. The Intermodal unit consists of a domestic segment and an 
               international segment that transport consumer and manufactured goods. 
               The Automotive unit is a carrier of automotive products originating 
               in southwestern Ontario and Michigan.
  </description>
  <category>Transportation</category>
  <link>http://www.cnrail.com</link>
  <year_high>53.75</year_high>
  <year_low>33.00</year_low>
  <pe_ratio>9.17</pe_ratio>
  <earnings>5.16</earnings>
  <yield>1.73</yield>
  <today open="47.70" high="48.14" low="46.63" current="47.19" vol="0.35" />
</stock>

<stock>
  <sName symbol="UNP">Union Pacific Corporation</sName>
  <description>Union Pacific Corporation operates primarily in the areas of rail 
               transportation, through its indirect wholly owned subsidiary Union 
               Pacific Railroad Company, and trucking, through its indirect wholly owned 
               subsidiaries Overnite Transportation Company and Motor Cargo Industries, 
               Inc. Union Pacific Railroad Company is a Class I railroad that operates 
               in the United States, with over 33,000 route miles linking Pacific Coast 
               and Gulf Coast ports to the Midwest and eastern United States gateways 
               and several north/south corridors to key Mexican gateways. Overnite is 
               a major interstate trucking company specializing in less-than-truckload 
               (LTL) shipments. Motor Cargo is a western regional LTL carrier that 
               provides service throughout 10 western states. The Company's other product 
               lines are comprised of the corporate holding company, which largely 
               supports the Railroad, Fenix LLC, affiliated technology companies and 
               self-insurance activities.
  </description>
  <category>Transportation</category>
  <link>http://www.up.com</link>
  <year_high>59.70</year_high>
  <year_low>58.15</year_low>
  <pe_ratio>14.32</pe_ratio>
  <earnings>4.06</earnings>
  <yield>1.38</yield>
  <today open="59.00" high="59.70" low="58.20" current="59.32" vol="1.81" />
</stock>

<stock>
  <sName symbol="ED">Consolidated Edison Corporation</sName>
  <description>Consolidated Edison, Inc. (Con Edison) is the holding company of 
               Consolidated Edison Company of New York, Inc. (Con Edison of New York) 
               and Orange and Rockland Utilities, Inc. (OR). Con Edison's principal 
               business segments are the regulated electric, gas and steam businesses 
               of its utility subsidiaries, and the unregulated businesses of its other 
               subsidiaries. Con Edison of New York provides electric service in all 
               of New York City (except part of Queens) and most of Westchester County, 
               an approximately 660-square-mile service area with a population of more 
               than eight million. It also provides gas service in Manhattan, The Bronx 
               and parts of Queens and Westchester, and steam service in part of 
               Manhattan, and its utility subsidiaries provide electric service in 
               southeastern New York and in adjacent sections of New Jersey and 
               northeastern Pennsylvania, an approximately 1,350 square mile service 
               area.
  </description>
  <category>Utilities</category>
  <link>http://www.conedison.com</link>
  <year_high>45.40</year_high>
  <year_low>35.50</year_low>
  <pe_ratio>11.76</pe_ratio>
  <earnings>3.16</earnings>
  <yield>5.98</yield>
  <today open="37.17" high="37.50" low="36.43" current="37.05" vol="1.22" />
</stock>

<stock>
  <sName symbol="AEP">American Electrical Power Company, Incorporated</sName>
  <description>American Electric Power Company, Inc. (AEP) is a public utility holding 
               company that directly or indirectly owns domestic electric utility 
               subsidiaries and varying percentages of other subsidiaries. The operating 
               revenues of AEP and its subsidiaries are mostly derived from the marketing 
               and trading of power and gas and the furnishing of electric service. The 
               Company's operations are divided into three business segments: Wholesale, 
               Energy Delivery and Other. The Wholesale Segment involves the generation 
               of electricity for sale to retail and wholesale customers, the marketing 
               and trading of electricity and gas worldwide, gas pipeline and storage 
               services, and other energy supply related business. The Energy Delivery 
               Segment is engaged in domestic electricity transmission and distribution. 
               The Other Segment involves foreign electricity generation investments, 
               foreign electricity distribution and supply investments, and 
               telecommunication services.
  </description>
  <category>Utilities</category>
  <link>http://www.aep.com</link>
  <year_high>48.90</year_high>
  <year_low>33.02</year_low>
  <pe_ratio>12.98</pe_ratio>
  <earnings>2.74</earnings>
  <yield>6.75</yield>
  <today open="36.10" high="36.42" low="34.35" current="34.45" vol="2.67" />
</stock>

<stock>
  <sName symbol="PPL">PPL Corporation</sName>
  <description>PPL Corporation is an energy and utility holding company. Through its 
               subsidiaries, PPL generates electricity in power plants in the 
               northeastern and western United States, markets wholesale or retail 
               energy primarily in the northeastern and western portions of the 
               United States and in Canada; delivers electricity to nearly six million 
               customers in the United States, United Kingdom and Latin America, and 
               provides energy services for businesses in the mid-Atlantic and 
               northeastern United States. PPL is organized in segments consisting of 
               Supply, Delivery and International. In addition, certain corporate 
               service functionsare provided by PPL Services, an unregulated subsidiary 
               of PPL.
  </description>
  <category>Utilities</category>
  <link>http://www.pplresources.com</link>
  <year_high>53.45</year_high>
  <year_low>28.54</year_low>
  <pe_ratio>11.10</pe_ratio>
  <earnings>2.69</earnings>
  <yield>4.82</yield>
  <today open="30.05" high="30.62" low="29.40" current="30.50" vol="0.84" />
</stock>

<stock>
  <sName symbol="MRO">Marathon Oil Corporation</sName>
  <description>Marathon Oil Corporation is engaged in the worldwide exploration and 
               production of crude oil and natural gas; domestic refining, marketing 
               and transportation of crude oil and petroleum products, primarily 
               through its 62%-owned subsidiary, Marathon Ashland Petroleum LLC (MAP), 
               and other energy-related businesses. Marathon is conducting exploration 
               and development activities in 11 countries. Refining, marketing and 
               transportation operations are primarily conducted by MAP and its 
               subsidiaries, including its wholly owned subsidiaries, Speedway 
               SuperAmerica LLC and Marathon Ashland Pipe Line LLC. Marathon also owns 
               interest in various pipeline systems that were not contributed to MAP. 
               Marathon, through its wholly owned subsidiary, Marathon Power Company, 
               Ltd., pursues development, construction, ownership and operation of 
               integrated gas and electric power projects in the global electrical 
               power market.
  </description>
  <category>Industrials</category>
  <link>http://www.marathon.com</link>
  <year_high>32.75</year_high>
  <year_low>23.28</year_low>
  <pe_ratio>8.36</pe_ratio>
  <earnings>2.86</earnings>
  <yield>3.85</yield>
  <today open="24.15" high="24.63" low="23.70" current="24.08" vol="1.84" />
</stock>

<stock>
  <sName symbol="AZO">Autozone Corporation</sName>
  <description>AutoZone, Inc. is a specialty retailer of automotive parts and 
               accessories, primarily focusing on do-it-yourself customers. Each 
               auto parts store carries an extensive product line for cars, vans and 
               light trucks, including new and re-manufactured automotive hard parts, 
               maintenance items and accessories. The Company also has a commercial 
               sales program in the United States that provides commercial credit and 
               prompt delivery of parts and other products to local repair garages, 
               dealers and service stations. AutoZone does not sell tires or perform 
               automotive repair or installation. In addition, the Company sells 
               automotive diagnostic and repair information software through its ALLDATA 
               subsidiary, and diagnostic and repair information through 
               alldatadiy.com.
  </description>
  <category>Industrials</category>
  <link>http://www.autozone.com</link>
  <year_high>84.50</year_high>
  <year_low>38.07</year_low>
  <pe_ratio>22.12</pe_ratio>
  <earnings>3.04</earnings>
  <yield>na</yield>
  <today open="68.00" high="69.30" low="65.80" current="67.19" vol="1.59" />
</stock>

</portfolio>

XSLT

<?xml version="1.0" encoding="UTF-8" ?>

<xsl:stylesheet version="1.0"
            xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="html" version="4.0" />

<xsl:template match="/">
<html>

    <head>
      <title>Hardin Financial</title>
    </head>
    <body>
      <h1 align="center">Current Stock Values</h1>

      <table border="2" align="center">
        <tr>
          <th>Stock</th>
          <th>Current</th>
          <th>Open</th>
          <th>High</th>
          <th>Low</th>
          <th>Volume</th>
        </tr>

          <xsl:for-each select="portfolio/stock">

            <tr>
            <td>
              <xsl:choose>
                <xsl:when test="today/@current &lt; today/@open">
                  <img src="down.gif" />
                </xsl:when>
                <xsl:when test="today/@current &gt; today/@open">
                  <img src="up.gif" />
                </xsl:when>
                <xsl:when test="today/@current &lt; today/@open">
                  <img src="down.gif" />
                </xsl:when>
                <xsl:otherwise>
                  <img src="same.gif" />
                </xsl:otherwise>
              </xsl:choose>

              <xsl:value-of select="sName/@symbol"/>
            </td>


            <xsl:apply-templates select="today/@open" />
            <xsl:apply-templates select="today/@high" />
            <xsl:apply-templates select="today/@low" />
            <xsl:apply-templates select="today/@current" />
            <xsl:apply-templates select="today/@vol" />
          </tr>

          </xsl:for-each>

      </table>

      <hr></hr>
      <hr></hr>

      <h1 align="center">Summary Information</h1>

      <xsl:for-each select="portfolio/stock">
      <xsl:apply-templates select="sName" />

      <table border="10" style="float:left" cellpadding="2" cellspacing="3">
        <tr>
          <td><b>Category</b></td>
          <td>
            <xsl:apply-templates select="category" />
          </td>
        </tr>
        <tr>
          <td><b>Year High</b></td>
          <td>
            <xsl:apply-templates select="year_high" />
          </td>
        </tr>
        <tr>
          <td><b>Year Low</b></td>
          <td>
            <xsl:apply-templates select="year_low" />
          </td>
        </tr>
        <tr>
          <td><b>P/E Ratio</b></td>
          <td>
            <xsl:apply-templates select="pe_ratio" />
          </td>
        </tr>
        <tr>
          <td><b>Earnings</b></td>
          <td>
            <xsl:apply-templates select="earnings" />
          </td>
        </tr>
        <tr>
          <td><b>Yield</b></td>
          <td>
            <xsl:apply-templates select="yield" />
          </td>
        </tr>

      </table>

      <xsl:apply-templates select="description" />

      </xsl:for-each>
      <br />
  </body>

</html>
</xsl:template>

<xsl:template match="@open|@high|@low|@current|@vol">
<td>
  <xsl:value-of select="." />
</td>
</xsl:template>

<xsl:template match="sName">
<h3 style="clear: left">
  <xsl:value-of select="." />
</h3>
</xsl:template>

<xsl:template match="description">
<p style="align: right">
  <xsl:value-of select="." />
</p>
</xsl:template>

<xsl:template match="category">
<td>
  <xsl:value-of select="." />
</td>
</xsl:template>

<xsl:template match="year_high">
<td>
  <xsl:value-of select="." />
</td>
</xsl:template>

<xsl:template match="year_low">
<td>
  <xsl:value-of select="." />
</td>
</xsl:template>

<xsl:template match="pe_ratio">
<td>
  <xsl:value-of select="." />
</td>
</xsl:template>

<xsl:template match="earnings">
<td>
  <xsl:value-of select="." />
</td>
</xsl:template>

<xsl:template match="yield">
<td>
  <xsl:value-of select="." />
</td>
</xsl:template>


</xsl:stylesheet>
4

0 回答 0