2013-09-05 11 views
0

Я хочу, чтобы сделать некоторые основные переназначения переменных в XSLT. Как это можно достичь?Как переназначить переменную в XSLT?

Я просто хочу, чтобы иметь возможность преобразовать это в XSLT (игнорируя функцию appendMonthWithZero()):

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, но он не работает. Я перекручивание через это в 12 раз, поэтому я хочу, чтобы сохранить изменения currentMonth среди других переменных:

<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 является декларативным языком, он не использует переменные состояния. Вам нужно решить, как выразить свой результат как функцию ввода, вместо того, чтобы думать о способе дать инструкции на уровне низкого уровня для компьютера.

В вашем случае это кажется очень простым; просто используйте разные переменные:

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

Когда я добавляю нуль в м2, должен ли я снова назначить другое значение? –

+0

Если вы добавляете нуль к значению, то вы создаете новое значение, да. –

Смежные вопросы