我是Umbraco CMS的新手。请帮忙。

我有一个Umbraco网站,我在其中创建了一个名为“ Master”的DocumentType。 “主”页面使用户可以输入目标和筹款筹款的目标,从而实现了他们正在进行的筹款。在“主”页面上,我有一个宏,该宏可以自动执行数学,以生成一个将在整个站点中使用的百分比。宏调用以下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>

这起作用了,但是我之所以假设是因为它是一个“ for-east”,它也返回了两个NAN结果。如何重写此(a)清洁剂和(b),以便它更好地工作。

我了解ASP.NET WebForms,因此,如果您可以比较它,它将有所帮助。

感谢帮助。

有帮助吗?

解决方案

在Umbraco中,您可以拥有所谓的递归值。这基本上是页面值,它查找节点hierachy,直到归档值。

这些也可以传递给宏。

因此,在您的情况下,假设您的宏称为“ charitytotaliser”,则可以使用以下宏调用:

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

$表示该值是递归的。

XSLT看起来像这样(不仅测试一个示例):

<?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>

如果需要,您还可以指定要传递的后备值(如果找不到递归值):

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

有关宏参数的更多信息,您可以阅读此信息 文档

其他提示

我只熟悉XSLT,因此,从这个角度来看,我建议您为您的详尽选择语句添加资格。我还没有看过XML,但是类似:

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

它只能浏览具有可以分配的目标量的。

不确定这是否是您所追求的,但我希望这会有所帮助。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top