xml与xsl的问题~,诚恳的向各位朋友请教。!

02-12-02 nmg






// 大家好:
我遇到一个问题,诚恳的向各位朋友请教。
在xsl中如何得到xml中的值
<input type=
"checkbox" name="checkbox" value="此处如何写" />
value应得到listUsers.xml文件中userId element的值
不知如何才能得到:(环境:win2000,tomcat3.2,IE6.0)

xml文件如下:
文件名:listUsers.xml
<?xml version=
"1.0" encoding="GB2312"?>
<?xml-stylesheet type=
"text/xsl" href="listUsers.xsl"?>
<Data>
<anRecord>
<userId>1</userId>
<userName>userName1</userName>
<password>password1</password>
</anRecord>
<anRecord>
<userId>2</userId>
<userName>userName2</userName>
<password>password2</password>
</anRecord>
<anRecord>
<userId>3</userId>
<userName>userName3</userName>
<password>password3</password>
</anRecord>
</Data>

xsl文件如下:
文件名:listUsers.xsl
<?xml version=
"1.0"?>
<xsl:stylesheet xmlns:xsl=
"http://www.w3.org/TR/WD-xsl">

<xsl:template match =
"/">

<html>
<head>
<META content=
"text/html; charset=gb2312" http-equiv="Content-Type"/>
<LINK href=
"../jsp/css/css1.css" rel="stylesheet" type="text/css"/>
</head>
<body bgColor=
"lavender">
<form action=
"../../servlet/myself.user.UsersServlet"
id=
"form1" method="post" name="form1">
<table border=
"1" bordercolordark="#ffffff" bordercolorlight="#666666" cellpadding="0" cellspacing="0" width="460" align="center">
<tr bgcolor=
"#666699">
<td width =
"30%" class="word2">
<div align=
"center">userId</div>
</td>
<td width =
"30%" class="word2">
<div align=
"center">userName</div>
</td>
<td width =
"30%" class="word2">
<div align=
"center">password</div>
</td>
</tr>

<xsl:for-each select=
"Data/anRecord">
<tr bgcolor=
"white">
<td width=
"150" height="6"></td>
<td width=
"150"></td>
<td width=
"150"></td>
</tr>
<tr>
<td width=
"150" bgcolor="#FFFFFF">
<input type=
"checkbox" name="checkbox" value="此处如何写" />
<xsl:value-of select=
"userId" />
</td>
<td width=
"150" bgcolor="#FFFFFF"><xsl:value-of select="userName" /></td>
<td width=
"150" bgcolor="#FFFFFF"><xsl:value-of select="password" /></td>
</tr>
</xsl:for-each>

</table>
<input id=
"submit" name="submit" style="HEIGHT: 35px; WIDTH: 80px" type="submit" value="delete"></input>
</form>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

nmg
2002-12-02 09:56

xml显示正常,但得不到checkbox的值!
诚恳的向各位朋友请教

jxb8901
2002-12-02 10:53

可以这样用:


<input type="checkbox" name="checkbox" onclick="alert(this.value);">
<xsl:attribute name=
"value">
<xsl:value-of select=
"userId" />
</xsl:attribute>
</input>

nmg
2002-12-02 11:30


多谢jxb8901!
您写的代码点后可以出个对话框,显示userId element 的值,
可是我是要把checkbox的value传到UsersSevlet中;
为了在UsersSevlet得到checkbox的value,checkbox 的value属性应该如何写呢
<input type="checkbox" name="checkbox" onclick="alert(this.value);" value="**什末**">
<xsl:attribute name=
"value">
<xsl:value-of select=
"userId" />
</xsl:attribute>
</input>
java代码:
String userId = request.getParameter(
"checkbox");

jxb8901
2002-12-02 11:42

xsl:attribute的作用就是给input增加一个属性,你的input中不需要再用value属性了, 我加一个alert是为了测试取得的value是否正确.

2Go 1 2 下一页