Logo 
Search:

Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

xsl formula not working right

  Asked By: Rachel    Date: Feb 11    Category: Sharepoint    Views: 2941

This may not be the place to ask, but I figured that since my xsl formula pulls
data from a SharePoint list, why not?

I have an xsl formula that is supposed to average a calculated value for a
column. My xsl looks like the following.


<xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row"/>
<xsl:variable name="Average" select="sum($Rows/@Resolution_x0020_Time) div
count($Rows/@Resolution_x0020_Time)"/>


Now, I checked this formula manually, and the result it is returning is
incorrect. 233 divided by 62 is not 0.74. I'm not sure if it's not counting
rows accurately, or of it's not adding the values in the calculated row
accurately.

If it will help the formula for the calculated row is as follows.

=IF(ISBLANK([Resolution Date]),[Today-Created],IF([Resolution
Date]-Created<0,0,([Resolution Date]-Created)))

Basically what the calculated column does is to check the "Resolution
Date" field to see if it has been populated, (since I have the "volatile"
[Today] operator in the formula,) if it has not been populated it counts the
days between the current day and the day the item was created, otherwise, if the
"Resolution Date" column is populated, it counts the days between the day that
the item was created and the day in the "Resolution Date" column. It works like
a charm. Except for the xsl formula. When I total the "Resolution Time" column
and then divide by the count of items, the answer that I get is very different
from the answer that is provided by the xsl formula. What is it not seeing, or
more appropriately, what am I not seeing?

(Just as an FYI, the xsl is part of a KPI webpart, and I can get the KPI
indicator to show the correct indicator by changing up the xsl variables a bit,
but then there is no value returned, so the indicator is pretty much
meaningless.)


If it will help, the rest of the xsl is here.


<xsl:template name="dvt_1">
<xsl:variable name="dvt_StyleName">Table</xsl:variable>
<xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row"/>
<xsl:variable name="Average" select="sum($Rows/@Resolution_x0020_Time) div
count($Rows/@Resolution_x0020_Time)"/>
<table border="0" width="100%" cellpadding="2" cellspacing="0">
<tr>
<td class="ms-vb" align="center" >
<span style="vertical-align:middle">
<xsl:if test="count($Rows)=0">
0 Days <img src="../images/KPI-0.gif"
style="vertical-align:middle"/>
</xsl:if>
</span>
<xsl:choose>
<xsl:when test="$Average < 3 and count($Rows)!= 0">
<xsl:value-of select="format-number($Average,
"###0.00;-###0.00")" />
Days <img src="../images/KPI-0.gif"
style="vertical-align:middle"/>
</xsl:when>
<xsl:when test="$Average > 5 and count($Rows)!= 0">
<xsl:value-of select="format-number($Average,
"###0.00;-###0.00")" />
Days <img src="../images/KPI-2.gif"
style="vertical-align:middle"/>
</xsl:when>
<xsl:when test="count($Rows)!= 0">
<xsl:value-of select="format-number($Average,
"#,##0.00;-#,##0.00")" />
Days <img src="../images/KPI-1.gif"
style="vertical-align:middle"/>
</xsl:when>
</xsl:choose>

Share: 

 

3 Answers Found

 
Answer #1    Answered By: Kacey Russo     Answered On: Feb 11

Without having the actual XML it's hard to guess where things go wrong.
Check if all @Resolution_x0020_Time fields have values.

While the count function will work, sum will give you a NaN if there's an issue
with the field values.
Test using:
Count: <xsl:value-of select="count($Rows/@Resolution_x0020_Time)" />
Sum: <xsl:value-of select="sum($Rows/@Resolution_x0020_Time)" />

 
Answer #2    Answered By: Rebecca Lewis     Answered On: Feb 11

Well using your idea I can see what values are returned, and for some reason, it
is not counting all of the rows in the list, and I'm sure that since it isn't
counting them all, it's not adding the value of that column to those rows
either. It's only counting 44 rows out of 64 rows. Not sure why that is.

 
Answer #3    Answered By: Emily Clark     Answered On: Feb 11

I got it figured out. It was limiting the results based on a view, and the I
had forgotten about the filtering in that view.

 
Didn't find what you were looking for? Find more on xsl formula not working right Or get search suggestion and latest updates.




Tagged: