Xml 我的XSL文档中的数字函数和格式有问题,结果文档中没有显示名称和百分比
我在这项任务上已经坚持了几个星期,我想我已经解决了大部分问题(如果有必要,请指出它们)。我正在完成一个XSL文档,该文档主要由教科书作者完成,它链接到一个预先制作的XML文档,该文档显示候选人姓名、选票计数、百分比、政党和地区。除了缺少候选人、地区、政党(D或R)的名称和投票百分比(百分比显示为NaN)外,页面呈现的内容基本正确。除此之外,它看起来很好,并且可以验证 “candidatePercent”变量包含分配给候选人的选票百分比,通过将“CandidateVoces”除以“TotalVoces”计算得出。这是我的密码:Xml 我的XSL文档中的数字函数和格式有问题,结果文档中没有显示名称和百分比,xml,xslt,Xml,Xslt,我在这项任务上已经坚持了几个星期,我想我已经解决了大部分问题(如果有必要,请指出它们)。我正在完成一个XSL文档,该文档主要由教科书作者完成,它链接到一个预先制作的XML文档,该文档显示候选人姓名、选票计数、百分比、政党和地区。除了缺少候选人、地区、政党(D或R)的名称和投票百分比(百分比显示为NaN)外,页面呈现的内容基本正确。除此之外,它看起来很好,并且可以验证 “candidatePercent”变量包含分配给候选人的选票百分比,通过将“CandidateVoces”除以“TotalVoc
<xsl:variable name="candidatePercent" select="($candidateVotes) div count($totalVotes)" />
<xsl:with-param name="cellCount" select="100 * round($candidatePercent)" />
在“drawCells”模板中,它表示使“cellCount”参数等于“candidatePercent”的值乘以100,并四舍五入到最接近的整数。这是我的密码:
<xsl:variable name="candidatePercent" select="($candidateVotes) div count($totalVotes)" />
<xsl:with-param name="cellCount" select="100 * round($candidatePercent)" />
以下是供参考的完整样式表:
<?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="/candidates/candidate" />
<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">
<xsl:variable name="candidateVotes" select="sum(votes)" />
<xsl:variable name="totalVotes" select="sum(..//votes)" />
<xsl:variable name="candidatePercent" select="($candidateVotes) div count($totalVotes)" />
<xsl:variable name="candidateName" select="$candidateInfo[@candidateID=current()/@candidateID]/name" />
<xsl:variable name="candidateParty" select="$candidateInfo[@candidateID=current()/@candidateID]/party" />
<tr>
<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(ScandidatePercent, '#0.0%')" />)
</th>y
<td>
<xsl:call-template name="drawCells">
<xsl:with-param name="cellCount" select="100 * round($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>
明尼苏达州国会选举结果
明尼苏达州国会选举结果
地区
候选人
投票
()
()
Y
XML文档(由教科书作者创建):
桑切斯,奥妮塔
D
伯克,托马斯
D
托马斯,霍华德
D
亲爱的,爱丽丝
D
艾肯,玛丽
D
尼尔森,凯文
D
斯图尔特普拉斯基
D
文,迈克尔
D
特劳特曼,瑞秋
R
蒋,迈克尔
R
奥尔森,弗雷德
R
格罗夫纳,斯图尔特
R
蒙德伯格,琳达
R
弗朗西斯,特雷弗
R
比尔森,南希
R
胡安·拉米雷斯
R
惠特曼,加里
我
拉森,艾丽西亚
我
道格拉斯夏皮罗
我
塞缪尔·里尔丁
我
凯特里克,瑞秋
我
英格尔松,雷
我
教皇,理查德
我
赞德,奥德利
我
其他
O
其他
O
其他
O
其他
O
其他
O
其他
O
其他
O
其他
O
谢谢。当然,在一些帮助下,我想我确实找到了答案(以及其他错误) 首先,我没有注意到我这里有一个大写的“S”`
()
而不是“$”。第二,我应该把“伯爵”从
`
对于全局变量,我也未能坚持使用中的document()函数。我认为,由于上周我几乎只使用了路径就完成了它,因此如果没有路径,它也可以工作。太长,读不下去了多加注意,使用更好的眼镜,不要把事情弄得更复杂
无论如何,我感谢你的帮助 你有一个全局变量,它只有在
候选者
是根元素时才有意义,你有一个地区
的模板,它只有在候选者
是地区
的子元素时才有意义。如果没有看到您的源文档,我们无法判断哪一个是错的,但它们不可能都是对的。@MichaelKay我明白了。作业告诉我创建候选全局变量,然后我在候选模板中创建变量,并调用drawCells模板及其参数。我已经用一个链接更新了这个帖子到源文档。谢谢。(1)请让Q独立。关于外部站点的数据,特别是drop box,往往是暂时的,而这个问题将在十年后出现,并且应该本身就有意义。(2) 将“候选者”作为根元素使用的样式表(通常)不适用于更丰富的congress.xml源文档:我现在不确定您的目标是哪一个。@MichaelKay我理解,但很遗憾,我不得不链接它,因为它远远超过了字符限制。“congress.xml”是我使用Web浏览器加载/处理的结果文档,因此这就是我的目标。很抱歉
<xsl:variable name="candidatePercent" select="($candidateVotes) div count($totalVotes)" />
`