+ -
当前位置:首页 → 问答吧 → 如何使用xmldom获得一个node的index

如何使用xmldom获得一个node的index

时间:2005-01-31

来源:互联网

期待ing。。。在不行就只好循环遍历了,我会哭死的,救救!

作者: bound0   发布时间: 2005-01-31

谢谢:)

作者: gorgee   发布时间: 2005-02-01

试试看这个例子能否解决你的疑问.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> New Document </TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author" CONTENT=""> <META NAME="Keywords" CONTENT=""> <META NAME="Description" CONTENT=""> <style> body,table { font-size:9pt; } </style> <xml id="xmlData"> <DATA> <LIST> <ITEM NAME="张三" GENDER="男" AGE="20"/> <ITEM NAME="李四" GENDER="女" AGE="30"/> <ITEM NAME="王麻子" GENDER="不明" AGE="40"/> </LIST> </DATA> </xml> <xml id="xslData"> <?xml version="1.0" encoding="GB2312" ?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:v="urn:schemas-microsoft-com:vml" version="1.0"> <xsl:output method="html" indent="yes"/> <xsl:template match="/"> <div align="center"> <xsl:apply-templates select="DATA"/> </div> </xsl:template> <xsl:template match="LIST"> <table backgcolor="silver" cellpadding="1" cellspacing="1" width="95%" bgcolor="silver" id="tblApplyList" align="center"> <tr bgcolor="#FFF4CA" height = "22"> <th width="20%" >姓名</th> <th width="30%">性别</th> <th width="20%" >年龄</th> <th width="30%">操作</th> </tr> <xsl:apply-templates select="ITEM"/> </table> </xsl:template> <xsl:template match="ITEM"> <tr bgcolor="white" > <td style="text-align:center"><xsl:value-of select="@NAME"/></td> <td style="text-align:center" ><xsl:value-of select="@GENDER"/></td> <td style="text-align:center" ><xsl:value-of select="@AGE"/></td> <td style="text-align:center" ><a href="#" onclick="DeleteItem({position()-1})">删除</a></td> </tr> </xsl:template> </xsl:stylesheet> </xml> <SCRIPT LANGUAGE="JavaScript"> <!-- function Init() { divData.innerHTML = xmlData.transformNode(xslData); } function DeleteItem(iIndex) { //alert(iIndex); var selectNode; selectNode = xmlData.selectNodes("//DATA/LIST/ITEM").item(iIndex); alert(selectNode.xml); //下面根据iIndex定位到xmldata } //--> </SCRIPT> </HEAD> <BODY onload="Init()"> <div id="divData"></div> </BODY> </HTML>
   提示:您可以先修改部分代码再运行

作者: bound0   发布时间: 2005-02-07