Новичок
Профиль
Группа: Участник
Сообщений: 7
Регистрация: 22.12.2009
Репутация: нет Всего: нет
|
Есть проблема, variable объявляется внутри темплейта, choose и when, вне этого choose'a переменная уже не видна. | Код | <?xml version="1.0" encoding="windows-1251"?> <?xml-stylesheet type='text/xsl' href='schema.xsl'?> <doc> <para>06543210</para> </doc>
|
| Код | <?xml version="1.0"?> <!DOCTYPE xsl:stylesheet SYSTEM "symbols.ent">
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/doc"> <HTML> <BODY> <PRE> <table cellpadding="3" cellspacing="1" style="text-align: center"> <tr> <xsl:call-template name="while"> <xsl:with-param select="normalize-space(para)" name="txt"/> <xsl:with-param name="width" select="(string-length(normalize-space(para)))"/> <xsl:with-param name="length" select="(string-length(normalize-space(para)))"/> </xsl:call-template> </tr>
<tr> <xsl:call-template name="caption"> <xsl:with-param select="03" name="month"/> <xsl:with-param select="09" name="year"/> <xsl:with-param select="(string-length(normalize-space(para)))" name="count"/> <xsl:with-param select="(string-length(normalize-space(para)))" name="length"/> </xsl:call-template> </tr> </table> </PRE> </BODY> </HTML> </xsl:template>
<xsl:template name="caption"> <xsl:param name="month"/> <xsl:param name="year"/> <xsl:param name="count"/> <xsl:param name="length"/>
<xsl:choose> <xsl:when test="$count != 0"> <xsl:variable name="p_month1" select="0"/> <td><xsl:value-of select="$p_month1"/></td> </xsl:when> </xsl:choose>
<xsl:choose> <xsl:when test="$count != 0"> <xsl:variable name="p_month" select="((($month)-(($length)-$count) mod 12))"/> <xsl:variable name="p_year" select="($year)-(format-number(($month+(($length)-$count)) div 12, '0'))" />
<xsl:choose> <xsl:when test="$p_month=1"> <xsl:choose> <xsl:when test="$p_year>10"> <td><xsl:value-of select="$p_year"/></td> </xsl:when> <xsl:otherwise> <td>0<xsl:value-of select="$p_year"/></td> </xsl:otherwise> </xsl:choose> </xsl:when> <xsl:otherwise> <xsl:choose> <xsl:when test="$p_month=1"> <td>Янв</td> </xsl:when> <xsl:when test="$p_month=2"> <td>Фев</td> </xsl:when> <xsl:when test="$p_month=3"> <td>Мар</td> </xsl:when> <xsl:when test="$p_month=4"> <td>Апр</td> </xsl:when> <xsl:when test="$p_month=5"> <td>Май</td> </xsl:when> <xsl:when test="$p_month=6"> <td>Июн</td> </xsl:when> <xsl:when test="$p_month=7"> <td>Июл</td> </xsl:when> <xsl:when test="$p_month=8"> <td>Авг</td> </xsl:when> <xsl:when test="$p_month=9"> <td>Сен</td> </xsl:when> <xsl:when test="$p_month=10"> <td>Окт</td> </xsl:when> <xsl:when test="$p_month=11"> <td>Ноя</td> </xsl:when> <xsl:when test="$p_month=0"> <td>Дек</td> </xsl:when>
</xsl:choose> </xsl:otherwise> </xsl:choose>
<xsl:call-template name="caption"> <xsl:with-param select="$month" name="month"/> <xsl:with-param select="$year" name="year"/> <xsl:with-param name="count" select="$count - 1"/> <xsl:with-param select="$length" name="length"/> </xsl:call-template> </xsl:when> <xsl:otherwise> </xsl:otherwise> </xsl:choose> </xsl:template>
<xsl:template name="while"> <xsl:param name="txt"/> <xsl:param name="width"/> <xsl:param name="length"/>
<xsl:choose> <xsl:when test="$width != 0"> <xsl:choose> <xsl:when test="substring($txt, ($length)-$width+1, 1)='C'"> <td bgcolor="#00FF00"><xsl:value-of select="substring($txt, ($length)-$width+1, 1)"/></td> </xsl:when> <xsl:when test="substring($txt, ($length)-$width+1, 1)='0'"> <td bgcolor="#FFFFFF;" style="border: 1px solid #CCCCCC"><xsl:value-of select="substring($txt, ($length)-$width+1, 1)"/></td> </xsl:when> <xsl:when test="substring($txt, ($length)-$width+1, 1)='1'"> <td bgcolor="#FCB7B7"><xsl:value-of select="substring($txt, ($length)-$width+1, 1)"/></td> </xsl:when> <xsl:when test="substring($txt, ($length)-$width+1, 1)='2'"> <td bgcolor="#FBA2A2"><xsl:value-of select="substring($txt, ($length)-$width+1, 1)"/></td> </xsl:when> <xsl:when test="substring($txt, ($length)-$width+1, 1)='3'"> <td bgcolor="#FA8686"><xsl:value-of select="substring($txt, ($length)-$width+1, 1)"/></td> </xsl:when> <xsl:when test="substring($txt, ($length)-$width+1, 1)='4'"> <td bgcolor="#F97070"><xsl:value-of select="substring($txt, ($length)-$width+1, 1)"/></td> </xsl:when> <xsl:when test="substring($txt, ($length)-$width+1, 1)='5'"> <td bgcolor="#FE5858"><xsl:value-of select="substring($txt, ($length)-$width+1, 1)"/></td> </xsl:when> <xsl:when test="substring($txt, ($length)-$width+1, 1)='6'"> <td bgcolor="#FC4141"><xsl:value-of select="substring($txt, ($length)-$width+1, 1)"/></td> </xsl:when> <xsl:when test="substring($txt, ($length)-$width+1, 1)='7'"> <td bgcolor="#FA2D2D"><xsl:value-of select="substring($txt, ($length)-$width+1, 1)"/></td> </xsl:when> <xsl:when test="substring($txt, ($length)-$width+1, 1)='8'"> <td bgcolor="#FF0000"><xsl:value-of select="substring($txt, ($length)-$width+1, 1)"/></td> </xsl:when> <xsl:when test="substring($txt, ($length)-$width+1, 1)='9'"> <td bgcolor="#A60000"><xsl:value-of select="substring($txt, ($length)-$width+1, 1)"/></td> </xsl:when> <xsl:when test="substring($txt, ($length)-$width+1, 1)='X'"> <td bgcolor="#000000" style="color: #FFFFFF"><xsl:value-of select="substring($txt, ($length)-$width+1, 1)"/></td> </xsl:when> </xsl:choose> <xsl:call-template name="while"> <xsl:with-param name="width" select="$width - 1"/> <xsl:with-param name="txt" select="$txt"/> <xsl:with-param select="$length" name="length"/> </xsl:call-template> </xsl:when> <xsl:otherwise> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet>
|
Т.е. в шаблоне caption объявляется переменная p_month1, вот она вне choose'a не видна. Почему?
|