xslt - SharePoint XSL Counter -


so i've been banging head against wall while , looking help. i'm trying create new itemstyle in sharepoint designer checks each item in task list , tallies total number of completed, in progress, , not started statuses. problem knowledge, xsl doesn't have mutable variables. have far this:

<xsl:variable name="schk">         <xsl:value-of select="@status"/> </xsl:variable>  <xsl:for-each select="@status">        <xsl:if test="$schk = 'completed' ">            <!-- add completed counter -->        </xsl:if>        <xsl:if test="$schk = 'in progress' ">                <!-- add in progress counter -->        </xsl:if>        <xsl:if test="$schk = 'not started' ">            <!-- add 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 --> 

any , appreciated, thanks!

edit: i've tried recursive method isn't working either...

<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>   

you correct in in xslt variables immutable. need use in case count function, counts items in node-set. this:

<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" /> 

of course, need replace 'task' ever element name using in xslt.

without seeing xml, hard give precise answer, example, consider following xml

<tasklist>    <task status="completed" />    <task status="completed" />    <task status="in progress" /> </tasklist> 

then xslt (to totals only), this

<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> 

notice how need positioned on parent element of individual 'task' elements here. alternative, can this...

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

which count task elements wherever in xml.

you following, if didn't know element name, sure there no other elements 'status' attibute:

<xsl:variable name="completed" select="count(//*[@status='completed'])" /> 

Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -