Logo 
Search:

Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

DVWP - XSL Recusions - simulating global variables

  Asked By: Chase    Date: Dec 14    Category: Sharepoint    Views: 2193

I have list of items and folders. I have a Data View Web Part that allows the
list to be navigated by it's folders. Inside a folder, it displays the items of
the folder and and all the sub folders with the number of items in those
folders.

Current Folder
- item 1
- item 2
- subfolder 1 (5 items)
- subfolder 2 (10 items)
- subfolder 3 (8 items)

I want to update this web part to show the total number of items in all the
subfolders.

Current Folder
- item 1
- item 2
- subfolder 1 (25 items) //imagine this folder has 2 subfolders - subsubfolder
1 (10) and subsubfolder 2 (10) -> 5 + 10 + 10 = 25
- subfolder 2 (34 items)
- subfolder 3 (16 items)

I have a recursion method that loops through each sub folder adding the current
number of items to the items in the subfolder but I'm getting the following
behavior. See end of post for my code (if you can follow it).

Current Folder
- item 1
- item 2
- subfolder 1 (2 10 10 items) //imagine this folder has 2 subfolders -
subsubfolder 1 (10) and subsubfolder 2 (10) -> 5 + 10 + 10 = 25
- subfolder 2 (4 10 10 10 items)
- subfolder 3 (6 10 items)


So instead of adding the items it's just printing them in a row. This would be
so easy in C# to have a global variable that would be used as a counter for the
total of each sub folder. How would you do this is XSL where there is no
updating of global variables?

/////
<xsl:variable name="CategoryCount">
<xsl:call-template name="folderCount">
<xsl:with-param name="CurrentItem" select="@FileRef"></xsl:with-param>
<xsl:with-param name="CurrentCount">0</xsl:with-param>
</xsl:call-template></xsl:variable> (<xsl:value-of
select="$CategoryCount"/> items)

//////

<xsl:template name="folderCount"> <xsl:param name="CurrentItem"/> <xsl:param
name="CurrentCount"/>
<!-- get the numbder of items in the current folder --> <xsl:variable
name="ParentPath" select="substring-after($CurrentItem,'/')"/> <xsl:variable
name="ChildLinks" select="/dsQueryResponse/Rows/Row[@ContentType='Link' and
@FileDirRef = $ParentPath]" /> <xsl:variable name="ChildLinksCount"
select="count($ChildLinks)"/>

<!--add the number of items to the running total -->
<xsl:variable name="NewCount" select="number($CurrentCount) +
number($ChildLinksCount)"></xsl:variable>

<!-- print the running total -->
<xsl:value-of select="number($NewCount)"/>

<!--get the sub folders --> <xsl:variable name="ChildFolders"
select="/dsQueryResponse/Rows/Row[@ContentType='Folder' and @FileDirRef =
$ParentPath]" /> <!-- Get the count for each sub folder --> <xsl:for-each
select="$ChildFolders"> <xsl:call-template name="folderCount">
<xsl:with-param name="CurrentItem" select="@FileRef"></xsl:with-param>
<xsl:with-param name="CurrentCount" select="$NewCount"></xsl:with-param>
</xsl:call-template> </xsl:for-each>
</xsl:template>

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on DVWP - XSL Recusions - simulating global variables Or get search suggestion and latest updates.




Tagged: