Link to home
Start Free TrialLog in
Avatar of lwebber
lwebber

asked on

XSL - count based on calculated value

I have a SharePoint data view web part based on a Task list. Task items have a field called @DueDate. I have created an XLS variable that uses the getDayDelta template from Marc Anderson's date_templates.xsl library. The attached code snippet shows the code for the table column that displays the "dueDateDelta", which is the number of days from today up to the DueDate. When the dueDateDelta is negative, the task is overdue.

This works perfectly, and my data vew web part shows the dueDateDelta correctly.

What I now need to do is include some xsl in the group header of the DVWP. I need to count up the number of rows with a dueDateDelta of < 0 (i.e. overdue tasks). I need a separate count of rows with a dueDateDelta > 0 and < 5. The end result will be a group header that displays the number of tasks that are overdue as well as the number of tasks that are close to being due.

I am stumped on how to do the XSL count. I need to restrict the count to rows where the table column whose ID = DDDelta (see the code snippet) has a value < 0. But how do I form an xsl count() that does this?  
<td class="ms-vb" id="DDDelta">
	<!-- get the delta in days between the due date and today -->
	<xsl:variable name="dueDateDelta">
		<xsl:call-template name="getDayDelta">
			<xsl:with-param name="paramDateA" select="@DueDate" />
			<xsl:with-param name="paramDateB" select="$Today" />
		</xsl:call-template>
	</xsl:variable>
	<xsl:if test="not(normalize-space(@DueDate) = '')">
		<span><xsl:value-of select="$dueDateDelta" /></span>
	</xsl:if>
</td>

Open in new window

Avatar of Marbleman
Marbleman

I cannot really imagine the XML you are talking about but the code you are looking for is probably this:

<xsl:value-of select="count(//pathto/myNodeName[@paramValue < $dueDateDelta])" />

Avatar of lwebber

ASKER

To understand the question, you need to look inside a SharePoint data view web part. It takes an xml data source and produces the html you see in a SharePoint web part. The finished web part has a table with a header row and a bunch of detail rows, one per record. You can edit the xsl template for a row and add columns to hold anything you like. I added a column to hold a computed field, and that's the snippet I posted.

The problem is that the scope of the xls template for creating detail rows is where my xsl code sits. That template "sees" the underlying xml data as attributes @this, @that, @theOther. It can also "see" the xsl variable I defined, because its scope is the row template where the other columns sit. The problem is that the *header* row of the table is in a separate xsl template, outside the scope of the $dueDateDelta. And it's a single row, where I want to present the *count* of all the detail rows below it, each of which is created by the xsl row template. So I'm trying to figure out how to count those rows, testing for a value of the $dueDateDelta (which I can't see from the place where I need to do the counting).
ok, i see... and understand...

the variable is specific to every dataset, correct?

Here is a real quick and dirty idea:

Make an html output for that variable everytime like this
<div id="dueDateDelta{@dataID}" class="dummyDiv" style="display: none;"><xsl:value-of select="$dueDateDelta"></div>

In the end you can access the data with javascript, collecting all divs of that class (if you need code for that let me know) and get the delta form div.innerHTML.

There is one problem left: when you render a script-block at the end of your code you should call the summing function with a window.timeout(sumFunc(), 1000) to make sure, the html is already rendered.

And: not all browsers render script blocks as they should. However IE does...

BTW: Instead of the div you could also use javascript to fill the data into an array:
<script type="text/javascript" >


</script>
ASKER CERTIFIED SOLUTION
Avatar of Marbleman
Marbleman

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lwebber

ASKER

Good idea. Javascript is going to be a whole lot easier for a procedural thinker like me. I'll try your suggestion and let you know.
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.