xsl模板中的参数值为null

时间:2014-04-21 13:20:46

标签: xslt

我正在调用模板如下:

<select class="inline" name="time-of-trip-begin-hour" id="time-of-trip-begin-hour">
                <xsl:call-template name="createDropDown">
                    <xsl:with-param name="count" select="23" />
                    <xsl:with-param name="selectedValue" select="$dropDownValue" />
                </xsl:call-template>
 </select>

Templete定义:

 <xsl:template name="createDropDown">
            <xsl:param name="index" select="0" />
            <xsl:param name="count" />
            <xsl:param name="selectedValue" />

            <xsl:if test="$index &lt;= 9">
                <option>
                    <xsl:attribute name="value">
                        <xsl:value-of select="concat('0',$index)" />
                    </xsl:attribute>

                    <xsl:value-of select="concat('0',$index)" />
                </option>
                <xsl:call-template name="createDropDown">
                    <xsl:with-param name="index" select="$index + 1" />
                    <xsl:with-param name="count" select="$count" />
                </xsl:call-template>
            </xsl:if>
            <xsl:if test="($index &gt; 9) and ($index &lt;= $count)">
                <option>
                    <xsl:attribute name="value">
                        <xsl:value-of select="$index" />
                    </xsl:attribute>

                    <xsl:if test=" $selectedValue = $index ">
                        <xsl:attribute name="selected">
                            <xsl:value-of select=" 'true' " />
                        </xsl:attribute>
                    </xsl:if>
                    <xsl:value-of select="$index" />
                </option>
                <xsl:call-template name="createDropDown">
                    <xsl:with-param name="index" select="$index + 1" />
                    <xsl:with-param name="count" select="$count" />
                </xsl:call-template>
            </xsl:if>
  </xsl:template>

但是,$selectedValue的值每次都为空,尽管$dropDownValue

中有值

1 个答案:

答案 0 :(得分:0)

您在代码中以递归方式调用模板两次,但在所有递归调用中都没有复制$selectedValue参数的值。

尝试将其添加到您的通话模板中:

<xsl:call-template name="createDropDown">
    <xsl:with-param name="index" select="$index + 1" />
    <xsl:with-param name="count" select="$count" />
    <xsl:with-param name="selectedValue" select="$selectedValue" />
</xsl:call-template>
相关问题