1

それで、私はしばらく壁に頭をぶつけていて、助けを探しています。基本的にタスクリストの各項目をチェックし、完了、進行中、および未開始のステータスの合計数を集計する、sharepoint デザイナーで新しい項目スタイルを作成しようとしています。問題は私の知る限り、xsl には変更可能な変数がありません。私がこれまでに持っているのはこれです:

<xsl:variable name="sChk">
        <xsl:value-of select="@Status"/>
</xsl:variable>
 <xsl:for-each select="@Status">
       <xsl:if test="$sChk = 'Completed' ">
           <!-- Add to Completed Counter -->
       </xsl:if>
       <xsl:if test="$sChk = 'In Progress' ">
               <!-- Add to In Progress Counter -->
       </xsl:if>
       <xsl:if test="$sChk = 'Not Started' ">
           <!-- Add to Not Started Counter -->
       </xsl:if>
        <br/>
    </xsl:for-each> 
    Out Of Loop:      
    Total Completed: <!-- Completed Value -->
    Total In Progress: <!-- In Progress Value -->
    Total Not Started: <!-- Not Started Value -->

ありとあらゆる助けをいただければ幸いです、ありがとう!

編集:だから私もこの再帰的な方法を試しましたが、これもうまくいきません...

<xsl:param name="cCount" select="0"/>
<xsl:param name="ipCount" select="0"/>
<xsl:param name="nsCount" select="0"/>

<xsl:choose>
    <xsl:when test="$sChk = 'Completed'">
        <xsl:call-template name="PSRView2.0">
            <xsl:with-param name="cCount" select="$cCount +1"/>
            <xsl:with-param name="ipCount" select="$ipCount"/>
            <xsl:with-param name="nsCount" select="$nsCount"/>              
        </xsl:call-template>
    </xsl:when>
    <xsl:when test="$sChk = 'In Progress'">
        <xsl:call-template name="PSRView2.0">
            <xsl:with-param name="cCount" select="$cCount"/>
            <xsl:with-param name="ipCount" select="$ipCount +1"/>
            <xsl:with-param name="nsCount" select="$nsCount"/>              
        </xsl:call-template>
    </xsl:when>
    <xsl:when test="$sChk = 'Not Started'">
        <xsl:call-template name="PSRView2.0">
            <xsl:with-param name="cCount" select="$cCount"/>
            <xsl:with-param name="ipCount" select="$ipCount"/>
            <xsl:with-param name="nsCount" select="$nsCount +1"/>               
        </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
        <xsl:value-of select="$cCount"/>
        <xsl:value-of select="$ipCount"/>
        <xsl:value-of select="$nsCount"/>
    </xsl:otherwise>
</xsl:choose>  
4

1 に答える 1

1

XSLT 変数は不変であるという点で正しいです。これらの場合に使用する必要があるのは、ノードセット内のすべてのアイテムをカウントするcount関数です。このようなもの:

<xsl:variable name="completed" select="count(task[@Status='Completed'])" />
<xsl:variable name="inprogress" select="count(task[@Status='In Progress'])" />
<xsl:variable name="notstarted" select="count(task[@Status='Not Started'])" />
Total: <xsl:value-of select="$completed + $inprogress + $notstarted" />

もちろん、'task' を XSLT で使用している要素名に置き換える必要があります。

XML を見ないと正確な答えを出すのは難しいですが、例として次の XML を考えてみましょう。

<tasklist>
   <task status="Completed" />
   <task status="Completed" />
   <task status="In Progress" />
</tasklist>

次に、XSLT (合計のみを取得するため) は次のようになります。

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:template match="tasklist">
        <xsl:variable name="completed" select="count(task[@Status='Completed'])" />
        <xsl:variable name="inprogress" select="count(task[@Status='In Progress'])" />
        <xsl:variable name="notstarted" select="count(task[@Status='Not Started'])" />
        Total: <xsl:value-of select="$completed + $inprogress + $notstarted" />
    </xsl:template>
</xsl:stylesheet>

ここで、個々の「タスク」要素すべての親要素に配置する必要があることに注意してください。別の方法として、次のようなことができます...

<xsl:variable name="completed" select="count(//task[@Status='Completed'])" />

XML 内のどこにいても、タスク要素をカウントします。

要素名を本当に知らなかったが、「ステータス」属性を持つ要素が他にないことを確信している場合は、次のことを行うこともできます。

<xsl:variable name="completed" select="count(//*[@Status='Completed'])" />
于 2013-08-12T22:15:46.563 に答える