我试图将三个节点加在一起以定义一个总值,但是当给定XML文档中不存在一个或多个选定节点时,得到的输出是“ NaN”。为节点“ double”,“ triple”和“ hr”定义默认值“ 0”(仅当给定XML中不存在该特定节点时才选择)的最简单方法是什么?
这是定义了所有节点的输入XML的示例:
<totals>
<hitting ab="32" r="9" h="9" rbi="9" double="3" triple="1" hr="1" bb="5" hbp="1" sh="1" so="4" gdp="1" ground="13" fly="6" kl="2" hitdp="1"></hitting>
<fielding po="27" a="13" e="1" csb="0" sba="2"></fielding>
<hsitsummary adv="3" fly="6" ground="13" lob="6" rcherr="1" rchfc="1" rbi-2out="6" vsleft="0,0" advops="13,23" leadoff="4,8" pinchhit="0,0" w2outs="3,10" wloaded="1,1" wrbiops="5,16" wrunners="6,19"></hsitsummary>
<pitching ip="9.0" ab="31" bb="1" bf="32" double="1" er="0" fly="5" ground="9" h="4" kl="2" r="0" so="12" sho="1"></pitching>
<psitsummary fly="5" ground="9" leadoff="3,9" wrunners="1,10" vsleft="2,15" w2outs="1,10"></psitsummary>
</totals>
当只定义一个(“ double”)时:
<totals>
<hitting ab="31" r="0" h="4" rbi="0" double="1" bb="1" sb="2" cs="1" so="12" ground="9" fly="5" kl="2"></hitting>
<fielding po="24" a="11" e="1" indp="1"></fielding>
<hsitsummary fly="5" ground="9" lob="5" rcherr="1" vsleft="0,0" advops="1,10" leadoff="3,9" pinchhit="0,2" w2outs="1,10" wloaded="0,0" wrbiops="0,7" wrunners="1,10"></hsitsummary>
</totals>
到目前为止,我已经尝试过XSLT转换,它显然仅在定义所有三个元素时才起作用。否则,它会吐出一个“ NaN”。
<xbh><xsl:value-of select="floor(totals/hitting/@double + totals/hitting/@triple + totals/hitting/@hr)" /></xbh>
代替totals/hitting/@double + totals/hitting/@triple + totals/hitting/@hr
使用sum(totals/hitting/@double | totals/hitting/@triple | totals/hitting/@hr)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句