Small width layout Medium width layout Maximum width layout Small text Medium text Large text
     Search
Downloads Downloads Directory Directory Forums Forums Forge Forge Blogs Blogs        Marketplace Marketplace Careers Program Careers
Community › Forums Register  |  

PortalWebHosting
  Ads  
 


  Sponsors  

Meet Our Sponsors

AspDotNetStoreFront - E-Commerce by Design - The Leading ASP.NET shopping cart platform for developers!
SteadyRain
DataSprings - Great Ideas. Always Flowing.
R2integrated - formerly bi4ce
Jango Studios - Skins, Modules and Hosting for DotNetNuke
eUKhost.com is commited to offer exceptional UK Windows Web Hosting solutions with quality 24x7 technical support.Our plans support ASP.Net, ASP, ASP.NET Ajax extensions, XML, MSSQL, MySQL, PHP,DNN, multiple domains and Shared SSL as standard.
 


DotNetNuke Forums
 
  Forum  DotNetNuke® Pro...  User Defined Ta...  Calculated Field
Previous Previous
 
Next Next
New Post 12/9/2006 7:26 AM
User is offline Tikkune
198 posts
9th Ranked




Re: Calculated Field 
Modified By Tikkune  on 12/9/2006 10:29:23 AM)

For the detailed info: thanks, Stefan. I now understand background info much more. But I do not yet understand which invisible column to reference, and how? I do need to create a Calculated column to grab the invisible column, yes?

I would like to display the Created At date, but in a format like MM/DD/YY, without the time detail.


"If a problem can be solved, there's no use worrying about it. If it can't be solved, worrying will do no good."
 
New Post 12/9/2006 7:53 AM
User is offline Stefan Cullmann
1553 posts
5th Ranked








Re: Calculated Field 
Modified By Stefan Cullmann  on 12/9/2006 10:54:40 AM)

Your wish is special, so you must go the hard way using string parsing. As a starting point I would suggest this template:

<xsl:template name="RenderDate">
 <xsl:param name="Value"/>
 <xsl:if test="$Value">
  <!--DateTime looks like "2005-12-31T23:59:55.0000000+01:00" -->
  <xsl:variable name="Year" select="substring($Value, 1, 4) "/>
  <xsl:variable name="Month" select="substring($Value, 6, 2) "/>
  <xsl:variable name="Day" select="substring($Value, 9, 2) "/>
  <xsl:variable name="Time" select="substring($Value, 12, 8) "/>
  <xsl:value-of select ="$Month"/>/<xsl:value-of select ="$Day"/>/<xsl:value-of select ="$Year"/>
 </xsl:if>
</xsl:template>


Stefan Cullmann - stefan.cullmann [at] dotnetnuke.com
form and List will be the successor of the User Defined Table module.
----------------------------------------------------------------------
Do you want to import external data to form and List /User Defined Table?
Check out http://www.codeplex.com/Csv2UDTImport
 
New Post 12/9/2006 8:51 AM
User is offline Tikkune
198 posts
9th Ranked




Running Total Column Maintained Across Rows 
Modified By Tikkune  on 12/9/2006 12:44:17 PM)
Pledged By Date Amount Balance
Stefan
12/09/2006
65
300
Tikkune
12/09/2006
50
250

Thank you, Stefan. Above is the UDT rendered result.

Your blog post:
http://www.dotnetnuke.com/Community/Blogs/tabid/825/EntryID/1038/Default.aspx

... is the foundation for this solution to track pledges for a donation pledge drive. It keeps track of who as pledged, when the pledge was made and what amount was pledged. Most importantly, it renders a running total of the outstanding balance due to reach the target amount, performed beautifully by the XSLT.

Here are the UDT columns:

CreatedBy
CreatedAt
ChangedBy
ChangedAt
Target (integer)
Pledge (integer)

... and here is the all important XSL transform that renders the UDT table at top (in UDT, to upload an XSL: Display Settings > Rendering Method > User Defined XSL Transformation):

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:udt="DotNetNuke/UserDefinedTable">
  <xsl:output omit-xml-declaration = "yes" />
  <xsl:template match="/" >
  <table  >
    <tr>
      <th/>
      <th>Pledged By</th>
      <th>Date</th>
      <th>Amount</th>
      <th>Balance</th>
    </tr>
      <xsl:for-each select ="/udt:UserDefinedTable/udt:Data">
        <tr class="normal">
          <!-- Alternate row formatting, position() will work like a row number -->
          <xsl:if test ="position() mod 2 =1">
            <!-- Attribute will be added to the <tr> tag -->
            <xsl:attribute name="style">background-color: aliceblue</xsl:attribute>
          </xsl:if>
          <!-- END alternate row formatting -->
          <td>
            <!-- Edit link, udt:EditLink will be missing if user does not have the needed permission -->
            <xsl:if test="udt:EditLink">
              <a>
                <xsl:attribute name="href">
                  <xsl:value-of select="udt:EditLink" />
                </xsl:attribute>
                <img border="0" alt="edit">
                  <xsl:attribute name="src">
                    <xsl:value-of select="//udt:Context/udt:ApplicationPath"/>/images/edit.gif
                  </xsl:attribute>
                </img>
              </a>
            </xsl:if>
            <!-- END Edit link -->
          </td>
          <td align="right">
            <xsl:value-of select="udt:CreatedBy"/>
            <br/>
          </td>
          <!-- CreatedAt looks like "2005-12-31T23:59:55.0000000+01:00" -->
          <xsl:variable name="Year" select="substring(udt:CreatedAt,1,4) "/>
          <xsl:variable name="Month" select="substring(udt:CreatedAt,6,2) "/>
          <xsl:variable name="Day" select="substring(udt:CreatedAt,9,2) "/>
          <xsl:variable name="Time" select="substring(udt:CreatedAt,12,8) "/>
          <td align="right">
            <xsl:value-of select ="$Month"/>/<xsl:value-of select ="$Day"/>/<xsl:value-of select ="$Year"/>
            <br/>
          </td>
          <td align="right">
            <xsl:value-of select="udt:Pledge"/>
            <br/>
          </td>
          <td align="right">
            <!-- Balance will be calculated and the value gets stored inside the variable $balance -->
            <xsl:variable name ="balance"
              select="sum((.|preceding-sibling::udt:Data)/udt:Target)
                     -sum((.|preceding-sibling::udt:Data)/udt:Pledge)"/>
            <span>
              <!-- Conditional formatting, the style attribute will be added to the <span> tag when balance < 0 -->
              <xsl:if test ="$balance&lt;0">
                <xsl:attribute name="style">color:red; font-weight: bold;</xsl:attribute>
              </xsl:if>
              <!-- Output $balance -->
              <xsl:value-of select="$balance"/>
            </span>
            <br/>   
          </td>
        </tr> 
     </xsl:for-each>
  </table>
  </xsl:template>
</xsl:stylesheet> 


"If a problem can be solved, there's no use worrying about it. If it can't be solved, worrying will do no good."
 
New Post 12/9/2006 11:03 AM
User is offline Stefan Cullmann
1553 posts
5th Ranked








Re: Running Total Column Maintained Across Rows 

Great. I love to see your progress. Next step is introducing more templates.  

A template separates the different concerns of you style sheet. For example you would prefer using a <xsl:apply-templates/> instead of a <xsl:for-each> in the most cases. I did not show it my examles to show the basic ideas. See http://www.w3schools.com/xsl/xsl_apply_templates.asp for more information.

Templates can also be used as functions. I will alter your script to show all concepts:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:udt="DotNetNuke/UserDefinedTable">
  <xsl:output omit-xml-declaration = "yes" />

  <xsl:template match="/" >
    <table  >
      <tr>
        <th/>
        <th>Pledged By</th>
        <th>Date</th>
        <th>Amount</th>
        <th>Balance</th>
      </tr>
      <xsl:apply-templates/>
    </table>
  </xsl:template>
    

  <xsl:template match="udt:UserDefinedTable/udt:Data">
     <tr class="normal">
        <!-- Alternate row formatting, position() will work like a row number -->
        <xsl:if test ="position() mod 2 =1">
          <!-- Attribute will be added to the <tr> tag -->
          <xsl:attribute name="style">background-color: aliceblue</xsl:attribute>
        </xsl:if>
        <!-- END alternate row formatting -->
        <td>
           <xsl:call-template name="ProvideEditLink"/>
        </td>
        <td align="right">
            <xsl:value-of select="udt:CreatedBy"/>
            <br/>
        </td>
        <td align="right">
           <xsl:call-template name="RenderDate">
              <xsl:with-param name="Value" select="udt:CreatedAt" />
           </xsl:call-template>
           <br/>
        </td>
        <td align="right">
          <xsl:value-of select="udt:Pledge"/>
          <br/>
        </td>
        <td align="right">
           <!-- Balance will be calculated and the value gets stored inside the variable $balance -->
           <xsl:variable name ="balance"
              select="sum((.|preceding-sibling::udt:Data)/udt:Target)
                     -sum((.|preceding-sibling::udt:Data)/udt:Pledge)"/>
           <span>
              <!-- Conditional formatting, the style attribute will be added to the <span> tag when balance < 0 -->
              <xsl:if test ="$balance&lt;0">
                 <xsl:attribute name="style">color:red; font-weight: bold;</xsl:attribute>
              </xsl:if>
              <!-- Output $balance -->
              <xsl:value-of select="$balance"/>
            </span>
            <br/>    
        </td>
      </tr>  
  </xsl:for-each>

  <xsl:template name="ProvideEditLink">
      <!-- Edit link, udt:EditLink will be missing if user does not have the needed permission -->
      <xsl:if test="udt:EditLink">
         <a>
           <xsl:attribute name="href">
             <xsl:value-of select="udt:EditLink" />
           </xsl:attribute>
           <img border="0" alt="edit">
             <xsl:attribute name="src">
                <xsl:value-of select="//udt:Context/udt:ApplicationPath"/>/images/edit.gif
             </xsl:attribute>
           </img>
         </a>
      </xsl:if>
      <!-- END Edit link -->
  </xsl:template>

     <xsl:template name="RenderDate">
    <xsl:param name="Value"/>
    <xsl:if test="$Value">
       <!--DateTime looks like "2005-12-31T23:59:55.0000000+01:00" -->
       <xsl:variable name="Year" select="substring($Value, 1, 4) "/>
       <xsl:variable name="Month" select="substring($Value, 6, 2) "/>
       <xsl:variable name="Day" select="substring($Value, 9, 2) "/>
       <xsl:variable name="Time" select="substring($Value, 12, 8) "/>
       <xsl:value-of select ="$Month"/>/<xsl:value-of select ="$Day"/>/<xsl:value-of select ="$Year"/>
    </xsl:if>
  </xsl:template>

</xsl:stylesheet> 


 


Stefan Cullmann - stefan.cullmann [at] dotnetnuke.com
form and List will be the successor of the User Defined Table module.
----------------------------------------------------------------------
Do you want to import external data to form and List /User Defined Table?
Check out http://www.codeplex.com/Csv2UDTImport
 
New Post 12/9/2006 2:18 PM
User is offline Tikkune
198 posts
9th Ranked




Re: Running Total Column Maintained Across Rows 
Modified By Tikkune  on 12/10/2006 6:50:33 PM)

I will have to study that one a bit, Stefan - but I certainly understand the value in structuring XSL in a modular, functional fashion. Thank you for taking the time to teach; it helps ALOT.


"If a problem can be solved, there's no use worrying about it. If it can't be solved, worrying will do no good."
 
Previous Previous
 
Next Next
  Forum  DotNetNuke® Pro...  User Defined Ta...  Calculated Field
 


Forum Policy

These Discussion Forums are dedicated to the discussion of the DotNetNuke Web Application Framework.

For the benefit of the community and to protect the integrity of the project, please observe the following posting guidelines:

1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DotNetNuke.
2. Discussion or promotion of DotNetNuke product releases under a different brand name are strictly prohibited.
3. No Flaming or Trolling.
4. No Profanity, Racism, or Prejudice.
5. Site Moderators have the final word on approving/removing a thread or post or comment.
6. English language posting only, please.

 


TMA Resources
TMA Resources is a software company providing eBusiness solutions for the Association market.
www.tmaresources.com
DotNetNuke Hosting Provider UK
UK leading DotNetNuke Hosting provider. Owned and operated by a Microsoft Gold Certified Partner.
www.DNN-Portals.co.uk
Alliance Systems & Programming Inc
Alliance is not just our name... it's how we do business. We partner with our clients, learning their business processes and standards and then applying our expertise to help them improve their workflow and profitability.
www.Alliancesys.com

DotNetNuke Corporation   Terms Of Use  Privacy Statement
DotNetNuke®, DNN®, and the DotNetNuke logo are trademarks of DotNetNuke Corporation
Hosted by MaximumASP