Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDNN Open Source...DNN Open Source...Module ForumsModule ForumsForm and ListForm and ListCalculated FieldCalculated Field
Previous
 
Next
New Post
12/9/2006 10:26 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 10:53 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>

 
New Post
12/9/2006 11:51 AM
 
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 2:03 PM
 

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> 


 

 
New Post
12/9/2006 5:18 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
 
Next
HomeHomeDNN Open Source...DNN Open Source...Module ForumsModule ForumsForm and ListForm and ListCalculated FieldCalculated Field


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, 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 DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out