我是XSL的新手,所以我真的不知道怎么做.我有一个for-each语句,它为类型“cell”的每个元素进行一些计算.如何总结结果并将它们存储在变量中,以便我可以显示它?我已经包含了部分代码.
我希望有人知道这个问题的解决方案.感谢您的时间和精力!
<?xml version="1.0"?> <xsl:stylesheet version="1.0"> <xsl:output media-type="xml" encoding="ISO-8859-1" indent="yes"/> <xsl:key name="object-map" match="/Data/Objects/*" use="@ExternalId"/> <xsl:template match="/"> <Data> <Objects> ... ... ... <xsl:for-each select="Data/Objects/Cell"> <xsl:attribute name="PpXmlVer"> <xsl:text>7.0</xsl:text> </xsl:attribute> ...................... <!--Calculating Machine Time: --> <Cell> <xsl:attribute name="ExternalId"> <xsl:value-of select="@ExternalId"/> </xsl:attribute> <!-- calculated.--> <FlipMachineTime> <xsl:choose> <xsl:when test="./FlipPlanedOccupationTime > 0"> <xsl:value-of select="here is a complicated formula to compute"/> </xsl:when> <xsl:otherwise>0</xsl:otherwise> </xsl:choose> </FlipMaschineTime> </Cell> </xsl:for-each> Here I would like to have the sum of FlipMachineTime for all encountered elements of type cell. ........... </Objects> </Data>
您需要创建一个变量来保存已计算的FlipMachineTime节点.然后你可以总结节点集.以下是一些示例代码:
<xsl:variable name="flipMachineTimes"> <xsl:for-each select="/Data/Objects/Cell"> <FlipMachineTime> <xsl:choose> <xsl:when test="./FlipPlanedOccupationTime > 0"> <xsl:value-of select="here is a complicated formula to compute"/> </xsl:when> <xsl:otherwise>0</xsl:otherwise> </xsl:choose> </FlipMachineTime> </xsl:for-each> </xsl:variable> <total> <xsl:variable name="myTotal" select="xalan:nodeset($flipMachineTimes)"/> <xsl:value-of select="sum($myTotal/FlipMachineTime)"/> </total>
要使其工作,请确保在样式表中包含xalan名称空间:
<xsl:stylesheet version="1.0" xmlns:xalan="http://xml.apache.org/xalan" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。