我再次有一个问题...

我从csvfile创建列表。我将字符串转换为date to dateTime类型:

 string[] formattedDates = { "dd.MM.yyyy HH:mm:ss", "mm:ss", "HH:mm:ss", "dd.MM.yyyy", "HH:mm:ss" };

 newEntry["Duration"] = DateTime.ParseExact("00:05", formattedDates, CultureInfo.InvariantCulture, DateTimeStyles.None);
.

但是当我检查我的数据列表 - 持续时间(例如:01:44,00:05)转换并显示如此如此8/27/2012 00:05(但它不是时间只是持续时间)

所以问题是:

  1. 如何使它以合适的格式显示在列表中(没有日期=“00:05”)?

  2. 将分钟00:05,00:41,01:03总和为01:49 - 总持续时间?

  3. 如果是2.是不可能的,你能提供你的解决方案吗?

有帮助吗?

解决方案

Many thanks to Marc D Anderson( [link] (http://sympmarc.com/2009/05/29/summing-calculated-columns-in-dvwps/)):

  1. call template

    <td class="ms-vh" nowrap="nowrap">                                              
    <xsl:variable name ="NodesTotals">                             
     <xsl:call-template name="TotalValue">
         <xsl:with-param name="Node" select="$nodeset"/>
     </xsl:call-template>                        
    </xsl:variable> 
        sum : <xsl:value-of select="$NodesTotals" />
    

  2. Sum rows

      <xsl:template name="TotalValue">
        <xsl:param name="Node"/>     
        <xsl:param  name="Sum" select="0"/>      
        <xsl:choose>
          <xsl:when test="$Node">
             <xsl:variable name="desimal">
                <xsl:value-of select="substring-before(ddwrt:FormatDateTime(string($Node[1]/@Duration),1033,'HH:mm'),':')*60 + substring-after(ddwrt:FormatDateTime(string($Node[1]/@Duration),1033,'HH:mm'),':')"/>
             </xsl:variable>
             <xsl:call-template name="TotalValue">
                <xsl:with-param name="Node" select="$Node[position()!=1]"/>
                <xsl:with-param name="Sum" select="$Sum + $desimal"/>
             </xsl:call-template>
    
          </xsl:when>   
          <xsl:otherwise><xsl:value-of select="$Sum"/></xsl:otherwise>    
       </xsl:choose>
     </xsl:template>
    

Thank you!

许可以下: CC-BY-SA归因
scroll top