어린이에게 사용하기 위해 부모 문서에서 속성에 액세스하려면 어떻게합니까?
문제
나는 Umbraco CMS를 처음 사용합니다. 도와주세요.
나는 '마스터'라는 문서 유형을 만든 Umbraco 웹 사이트가 있습니다. '마스터'페이지를 통해 사용자는 자금 조달이 시작된 펀드 인상의 목표와 금액을 입력 할 수 있습니다. '마스터'페이지에는 자동으로 수학을 수행하여 사이트 전체에 사용될 퍼센트를 생성하는 매크로가 있습니다. 매크로는 다음 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>
이것은 효과가 있지만, 나는 그것이 '특별한'이기 때문에 두 가지 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 " "> ]>
<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>
목표 금액이있는 것만으로 나눌 수있는 것만 걸어야합니다.
이것이 당신이 추구하는지 확실하지 않지만 이것이 도움이되기를 바랍니다.