views:

92

answers:

2

I am new to Umbraco CMS. PLease help.

I have a Umbraco website in which I created a DocumentType called 'Master'. The 'Master' page lets user input a goal and amount for a fund raising initiate they are undertaking. On the 'Master' page I have a Macro which automatically does the math to generate a percent that will be used throughout the site. The Macro calls the following XSLT

 <xsl:for-each select="$currentPage/ancestor-or-self::*">
  <xsl:variable name="amount" select="* [@alias = 'FundraisingCurrentAmount']"/>
  <xsl:variable name="goal" select="* [@alias = 'FundraisingGoal']"/>
  <xsl:variable name="percentage" select="$amount div $goal * 100"/>
  <xsl:value-of select="$percentage"/>
 </xsl:for-each>

This works but, I am assuming because it is a 'for-each' it is also returning two NaN results. How can I rewrite this (a) cleaner and (b) so that it works better.

I understand ASP.NET Webforms so if you could compare to that it'd help out.

Appreciate the help.

+1  A: 

I am only familiar with XSLT, so from that standpoint I suggest adding a qualification for your for-each select statement. I haven't seen the XML but something like:

<xsl:for-each select="$currentPage/ancestor-or-self::*[FundraisingGoal>0]">
.
.
.
</xsl:for-each>

It should only walk through the ones that have a goal amount that can be divided by.

Not sure if this is what you are after, but I hope this helps.

dredful
I know it's not *strictly required* in this case, but I'd opt for using `>` in place of `>`, not only because the latter breaks the Stack Overflow syntax highlighter.
Tomalak
Agreed. I usually type it > instead of > initially and then wonder why XSLT is invalid. :)
dredful
+1  A: 

Hi,

In Umbraco you can have what are called recursive values. This are basically page values which look up the node hierachy until it filnds a value.

These can be passed to macros as well.

So in your case assuming your macro is called "charityTotaliser" you could use the following macro call:

<umbraco:macro alias="charityTotaliser" ammount="[$FundraisingCurrentAmount]" goal="[$FundraisingGoal]"runat="server"/>

The $ indicates that the value is recursive.

The XSLT would look something like this (not tested just an example):

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:Stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
<xsl:stylesheet 
    version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:msxml="urn:schemas-microsoft-com:xslt"
    xmlns:umbraco.library="urn:umbraco.library"
    xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath"
    exclude-result-prefixes="msxml umbraco.library Exslt.ExsltMath">

    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>

    <!-- Macro parameters -->
    <xsl:variable name="FundraisingCurrentAmount" select="/macro/FundraisingCurrentAmount"/>
    <xsl:variable name="FundraisingGoal" select="/macro/FundraisingGoal"/>

    <xsl:template match="/">

        <xsl:value-of select="$FundraisingCurrentAmount div $FundraisingGoal * 100"/>

    </xsl:template>

</xsl:stylesheet>

If requied you can also specify fallback values to be passed (in case the recursive value cannot be found):

<umbraco:macro alias="charityTotaliser" ammount="[$FundraisingCurrentAmount], [#FallBackAmmount], 1234" goal="[$FundraisingGoal]"runat="server"/>

For more information on macro parameters you can read this documentation

Tim Saunders