2016-04-18 13 views
0

ブラウザでXMLファイル(congress.xml)を表示するとき、election.xslのdrawCellsテンプレートは適切なビジュアル要素を生成していないようです。生成された棒グラフがあるはずですが、そうではありません。XSLスタイルシートテンプレートが適切なビジュアル要素を生成しない

ブラウザでcongress.xmlを開きます。テキストエディタでelections.xslを開きます。

ファイルがある...ここ

congress.xml 
election.xsl 
candidates.xml 
vwstyles.css 
vwlogo.png 

は、ここですべてのファイル... https://drive.google.com/folderview?id=0B9o30hEqwvyDc2Y3MktHNDQydnc&usp=sharing

ためにGoogleドライブリンクで起きていることになっているもののイメージが..です。

vw.jpg

あなたはこの選挙を見て、起きていない理由あなたが見ることができると思います。 XSLスタイルシートitelselfは、ここでは

<?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" 
     doctype-system="about:legacy-compat" 
     encoding="UTF-8" 
     indent="yes" /> 


    <xsl:variable name="candidateInfo" select="document('candidates.xml')/candidates/candidate[@candidateID]" /> 


    <xsl:template match="/"> 
     <html> 
     <head> 
      <title>Minnesota Congressional Election Results</title> 
      <link href="vwstyles.css" rel="stylesheet" type="text/css" /> 
     </head> 

     <body> 
      <div id="wrap"> 
       <header> 
        <img src="vwlogo.png" alt="Voter Web" /> 
       </header> 

       <h1>Minnesota Congressional Election Results</h1> 

       <section id="votingResults"> 
        <xsl:apply-templates select="congressResults/district" /> 
       </section> 

      </div> 
     </body> 
     </html> 
    </xsl:template> 

    <xsl:template match="district"> 
     <h2>District <xsl:value-of select="@dNumber" /></h2> 
     <table class="electionTable"> 
     <thead> 
      <tr> 
       <th>Candidate</th> 
       <th>Votes</th> 
      </tr> 
     </thead> 
     <tbody> 
      <xsl:apply-templates select="candidates/candidate" /> 
     </tbody> 
     </table> 
    </xsl:template> 

    <xsl:template match="candidate"> 
     <tr> 

     <xsl:variable name="candidateVotes" select="sum(votes)" /> 
     <xsl:variable name="totalVotes" select="sum(..//votes)" /> 
     <xsl:variable name="candidatePercent" select="($candidateVotes) div ($totalVotes)" /> 
     <xsl:variable name="candidateName" select="$candidateInfo[@candidateID=current()/@candidateID]/name" /> 
     <xsl:variable name="candidateParty" select="$candidateInfo[@candidateID=current()/@candidateID]/party" /> 

     <th>    
      <xsl:value-of select="$candidateName" /> 
      (<xsl:value-of select="$candidateParty" />)   
     </th> 

     <th> 
      <xsl:value-of select="format-number($candidateVotes, '###,##0')" /> 
      (<xsl:value-of select="format-number($candidatePercent, '#0.0%')" />) 
     </th> 

     <td> 
      <xsl:call-template name="drawCells"> 
       <xsl:with-param name="cellCount" select="round(100 * $candidatePercent)"/> 
       <xsl:with-param name="party" select="$candidateParty" /> 
      </xsl:call-template> 
     </td> 



     </tr> 
    </xsl:template> 

    <xsl:template name="drawCells"> 
     <xsl:param name="cellCount" /> 
     <xsl:param name="party" /> 
     <xsl:if test="$cellCount > 0"> 
     <td class="{$party}"></td> 
     <xsl:call-template name="drawCells"> 
      <xsl:with-param name="cellCount" select="$cellCount - 1" /> 
      <xsl:with-param name="party" select="$party" /> 
     </xsl:call-template> 
     </xsl:if> 
    </xsl:template> 

</xsl:stylesheet> 

答えて

2

あなたはそのためtdのネスト、自身のtd要素にdrawCellsへの呼び出しをラップ...です:

<td> 
    <xsl:call-template name="drawCells">...</<xsl:call-template> 
</td> 

をする代わりに、単純に行う

<xsl:call-template name="drawCells">...</<xsl:call-template> 

少なくともこれはFirefoxでの出力を修正します。

+0

ありがとうございます!それはそれを修正した。 – codeRed

関連する問題