質問

私はこれを持っています(タスクを解決する試み):

<xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal">
  <xsl:output method="html" indent="no"/>
  <xsl:decimal-format NaN=""/>  
     <xsl:template match="/">
      <xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row"/>
        <xsl:value-of select="sum($Rows/@Distance[.!=''])" />

    </xsl:template>

</xsl:stylesheet>

結果は次のとおりです。「ナン」なので、XSLTが間違っていると思います。

質問:XSLTを記述して、データビューWebパーツの「距離」列のすべての値の合計を計算して表示するにはどうすればよいですか?列には空の値があります(ちなみに空の値はありません)これは、合計を計算することを無視する必要があります。

更新1:

<xsl:decimal-format grouping-separator="." decimal-separator="," NaN="" name="european"/>
<xsl:template match="/">

テスト:

<xsl:copy-of
    select="format-number(sum(for ($i in /dsQueryResponse/Rows/Row/@Distance) { return number(replace($i, ',','.')})), '#,##', 'european')" />

これを試しましたが、失敗します(プロセッサstyleSheetの設定に失敗しました。

更新2:

<xsl:template match="/">
    	xsum //Distance = <xsl:call-template name="xsum"><xsl:with-param name="currnode" select="//row/@Distance[1]"/></xsl:call-template>    		

    <xsl:template name="xsum">
        	<xsl:param name="currnode"/>
    	<xsl:param name="res" select="0"/>
    	<xsl:choose>
            		<xsl:when test="$currnode">
                			<xsl:call-template name="xsum">
                    			<xsl:with-param name="currnode" select="$currnode/following-sibling::tal[1]"/>
    		             		<xsl:with-param name="res" select="$res + translate($currnode,',','.')"/>
    		            	</xsl:call-template>
            		</xsl:when>
            		<xsl:otherwise>
                			<xsl:value-of select="translate($res,'.',',')"/>
            		</xsl:otherwise>
        	</xsl:choose>
    </xsl:template>

上記のXSLTを持っていますが、出力を提供しますが、距離列に次の値があります。

2 
3,5 
-1,3
0

結果はNANとは異なりますが、合計ではなく、私が見る限りの最初の値だけです。結果は次のとおりです。xsum//距離= 2。

更新3:

これは機能します。開始ノードの選択にいくつかの問題がありましたが、それを修正する必要があります。

<xsl:decimal-format name="da-DK" decimal-separator="," grouping-separator="." minus-sign="-" NaN="Ikke tal"/>

   <xsl:output method="html"/>      
    <xsl:template match="/"> 
        <xsl:text>Distance tilbagelagt = </xsl:text>        
        <xsl:call-template name="xsum">
            <xsl:with-param name="currnode" select="//Row[1]"/>
            <xsl:with-param name="attr-type" select="'Distance'"/>
            <xsl:with-param name="res" select="0"/>
        </xsl:call-template> km


    <xsl:template name="xsum"> 
        <xsl:param name="currnode"/>
        <xsl:param name="attr-type"/>
        <xsl:param name="res" select="0"/> 
        <xsl:choose> 
            <xsl:when test="$currnode/following-sibling::Row"> 
                <xsl:call-template name="xsum"> 
                    <xsl:with-param name="currnode" select="$currnode/following-sibling::Row[1]"/>
                    <xsl:with-param name="attr-type" select="$attr-type"/>
                    <xsl:with-param name="res" select="$res + number(translate($currnode/@*[name() = $attr-type],',','.'))"/> 
                </xsl:call-template> 
            </xsl:when> 
            <xsl:otherwise> 
                <xsl:value-of select="format-number($res + number(translate($currnode/@*[name() = $attr-type],',','.')), '#,##','da-DK')"/> 
            </xsl:otherwise> 
        </xsl:choose> 
    </xsl:template>
役に立ちましたか?

他のヒント

これは機能するはずです:

<xsl:value-of select="sum($Rows[string-length(@Distance) &gt; 0]/@Distance)" />

M.

ライセンス: CC-BY-SA帰属
所属していません sharepoint.stackexchange
scroll top