Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 15th, 2007, 07:21 AM
Registered User
 
Join Date: Aug 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSL:Variable SELECT=sum(condictions)

Hi,

I'm a noob in XSL and need some help.
Look at the code below and, mainly, the bold lines.


<xsl:stylesheet version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Microsoft.SharePoint.WebControls " xmlns:ddwrt2="urn:frontpage:internal">
    <xsl:output method="html" indent="no"/>
    <xsl:decimal-format NaN=""/>
    <xsl:param name="dvt_apos">'</xsl:param>
  <xsl:param name="Today">CurrentDate</xsl:param>
    <xsl:variable name="dvt_1_automode">0</xsl:variable>
    <xsl:template match="/" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:SharePoint="Microsoft.SharePoint.WebControls ">
        <xsl:call-template name="dvt_1"/>
    </xsl:template>
    <xsl:template name="dvt_1">
        <xsl:variable name="dvt_StyleName">Table</xsl:variable>
        <xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row"/>
    <xsl:variable name="Hoje" select="$Today-7"/>
    <xsl:variable name="Average" select="sum($Rows[@Created=$Hoje]/@ResolveTime) div count($Rows[@Created=$Hoje]/@ResolveTime)"/>

     <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 or $Average=0">
0
<xsl:text xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" ddwrt:whitespace-preserve="yes" xml:space="preserve" > Dias </xsl:text>
<img src="../images/KPI-0.gif" style="vertical-align:middle"/>
</xsl:if>
</span>
 <!-- <where>
    <gt>
      <FieldRef Name="Created" Nullable="True" Type="DateTime" />
      <Value Type="DateTime">
        <Today OffSetDays="-7" /><Value Type="DateTime" IncludeTimeValue="TRUE"><Today /></Value>"
      </Value>
    </gt>
  </where>-->
  <xsl:choose>
    <xsl:when test="$Average &lt; 60 and count($Rows)!= 0">
      <xsl:value-of select="format-number($Average, &quot;###0;-###0&quot;)" />
      <xsl:text xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" ddwrt:whitespace-preserve="yes" xml:space="preserve" > Dias </xsl:text>
      <img src="../images/KPI-0.gif" style="vertical-align:middle"/>
    </xsl:when>
    <xsl:when test="$Average &gt; 60 and $Average &lt; 120 and count($Rows)!= 0">
      <xsl:value-of select="format-number($Average, &quot;###0;-###0&quot;)" />
      <xsl:text xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" ddwrt:whitespace-preserve="yes" xml:space="preserve" > Dias </xsl:text>
      <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, &quot;###0;-###0&quot;)" />
      <xsl:text xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" ddwrt:whitespace-preserve="yes" xml:space="preserve" > Dias </xsl:text>
      <img src="../images/KPI-1.gif" style="vertical-align:middle"/>
    </xsl:when>
    </xsl:choose>

</td>
</tr>
<tr valign="top">
            <td align="center" >

<table><tr><td class="ms-vb" >
         <img src="../images/KPI-0.gif" align="absmiddle" /> &lt;= 60 Minutos<br/>
         <img src="../images/KPI-1.gif" align="absmiddle" /> &lt;= 120 Dias<br/>
         <img src="../images/KPI-2.gif" align="absmiddle" /> 5+ Dias<br />
</td></tr></table>
      </td>
</tr>
        </table>
    </xsl:template>
</xsl:stylesheet>


Thx,

Andre


 
Old August 15th, 2007, 07:58 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You don't have a variable called $Today-7. Perhaps you meant the "-" to be minus rather than hyphen, in which case it needs to have spaces around it. Perhaps you're trying to subtract a duration from a date? In that case you need XSLT 2.0.

Whatever it is (a) you seem to be making guesses as to what code to write, and (b) you seem to be expecting other people to make guesses as to what your incorrect code was designed to do.

It's better to describe your problem rather than just showing code that doesn't work.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old August 15th, 2007, 08:30 AM
Registered User
 
Join Date: Aug 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I need to use the Average variable to get the sum of @ResolveTime in the rows where @Created is in one week before.
<xsl:variable name="Average" select="sum($Rows[@Created=$Hoje]/@ResolveTime) div count($Rows[@Created=$Hoje]/@ResolveTime)"/>

Yes, I'm trying to use the variable called Hoje to get data from one week before today.
<xsl:variable name="Hoje" select="$Today - 7"/>

Thx,

AR

 
Old August 15th, 2007, 08:51 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Well, subtracting the number 7 from the string "CurrentDate" won't do it. Computers aren't good at guessing the intentions of the programmer. You might have meant 7 years...

In XSLT 2.0 you can subtract the duration xs:duration('PT7D') from the date obtained using the function current-date().



Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
passing javascript variable in xsl:value-of select eruditionist XSLT 2 September 19th, 2008 05:23 PM
xsl:param and xsl:apply-templates' "select" newbieboobers XSLT 1 March 25th, 2008 07:23 PM
Populating a Select Control from an XSL:Variable pcahaus XSLT 1 October 31st, 2007 04:21 AM
ASSIGNING A JAVA SCRIPT VARIABLE TO A XSL VARIABLE SOMANATHAN10 XSLT 1 February 21st, 2007 04:26 AM
<xsl:for-each> with a variable select="attribute" BeneathClouds XSLT 1 August 1st, 2005 03:36 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.