多条具有相同name属性的select回显,如图所示
比如:学习类型
<select name="studytype" id="studytype{position()}" size="1" >
<option value="">请选择...</option>
<xsl:for-each select="/root/studyTypeList">
<option value="{@studyType}"><xsl:value-of select="@studyType"/></option>
</xsl:for-each>
</select>
<script language="javascript">
form1.studytype<xsl:value-of select='position()' />.value = "<xsl:value-of select="@studytype" />";
</script>
servlet获取学习类型的时候通过select的name属性,在xsl里回显的时候通过select的id属性。通过xsl提供的position()方法获取到每一条记录在前台的编号和name组合成为惟一的id。
如果是单条显示还可以通过另一种方法,如下:
<select name="studytype" size="1" >
<xsl:for-each select="/root/studyTypeList">
<xsl:element name="option">
<xsl:attribute name="value">
<xsl:value-of select="@studyType"></xsl:value-of>
</xsl:attribute>
<xsl:if test="/root/studyxp/@studytype= @studyType">
<xsl:attribute name="selected">
true
</xsl:attribute>
</xsl:if>
<xsl:value-of select="@studyType"></xsl:value-of>
</xsl:element>
</xsl:for-each>
</select>