2013-09-05 2 views
0

저는 XSLT에서 몇 가지 기본적인 재 할당을 할 수 있기를 원합니다. 어떻게이 일을 성취 할 수 있습니까?XSLT에서 변수를 어떻게 재 할당합니까?

난 그냥합니다 (appendMonthWithZero() 함수를 무시) XSLT이 변환 할 수 있도록하려면 :

if(currentMonth + count > 12) //If we get past December onto a new year we need to reset the current month back to 01 
{ 
    currentMonth = (currentMonth + count) - 12; //e.g. 9 + 4 = 13, 13 - 12 = 1 (January). Or 9 + 11 = 20, 20 - 12 = 8 (August) 
    if(currentMonth < 10) 
    { 
     currentMonth = appendMonthWithZero(); 
    } 
} 

지금까지 나는 XSLT이있다 그러나 그것은 작동하지 않습니다.

<xsl:if test="$currentMonth + $count &gt; 12"> 
    <xsl:param name="currentMonth" select="($currentMonth + $count) - 12"/> 
</xsl:if> 

이것은 내가 의사 전반적인 할 노력하고있어 본질적으로 무엇을 (http://pastebin.com/WsaZaKnC을) :

currentMonth = getCurrentMonth(); 
actualDateWithZero = appendMonthWithZero(); 
docs = getFlightResults(); 
monthsArray = ['Jan', 'Feb', 'Mar'.......]; 

for(count = 0; count < 12; count++) 
{ 
    outboundMonth = subString(doc[count+1].getOutboundMonth()); 

    if(currentMonth + count > 12) //If we get past December onto a new year we need to reset the current month back to 01 
    { 
     currentMonth = (currentMonth + count) - 12; //e.g. 9 + 4 = 13, 13 - 12 = 1 (January). Or 9 + 11 = 20, 20 - 12 = 8 (August) 
     if(currentMonth < 10) 
     { 
      currentMonth = appendMonthWithZero(); 
     } 
    } 

    //A price is available. 
    //Second check is for when we get past a new year 
    if(currentMonth + count == outboundBoundMonth || currentMonth == outboundMonth) 
    { 
     //Get rest of data from doc etc etc 
     //Set up divs etc etc 
     //Get string month with displayed Month [Jan, Feb, Mar....] 
    } 

    //Else no price available for this month 
    else 
    {  
     //display price not available 
     //Get string month with displayed Month [Jan, Feb, Mar....] 
    } 
} 

답변

2

XSLT를 내가 다른 변수 사이에 currentMonth를 수정 유지하려면, 그래서 나는이를 통해 12 회 반복하고 선언적 언어이므로 상태 변수를 사용하지 않습니다. 저수준의 절차 적 지침을 컴퓨터에 제공하는 방법을 생각하기보다는 입력 내용에 따라 출력을 표현하는 방법을 알아야합니다.

매우 간단합니다.

if(currentMonth + count > 12) { 
    m2 = (currentMonth + count) - 12; 
    if (m2 < 10) then appendMonthWithZero(m2) else m2; 
} else { 
    currentMonth 
} 
+0

m2에 0을 추가 할 때 다시 다른 값을 할당해야합니까? –

+0

값에 0을 추가하면 새 값인 yes가 작성됩니다. –

관련 문제