首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

高分求 js 对xml 模糊查询 代码,已传例子代码

2011-12-26 
高分求 js 对xml 模糊查询 代码,已传事例代码下面从网上找的代码,改模糊查询即可,search.xml?xmlversion

高分求 js 对xml 模糊查询 代码,已传事例代码
下面从网上找的代码,改模糊查询即可,

search.xml  
<?xml   version= "1.0 "   encoding= "gb2312 "   ?>
<?xml-stylesheet   type= "text/xsl "   href= "search.xsl "   ?>
<BlueIdea>
    <team>
        <blue_ID> 1 </blue_ID>
        <blue_name> Sailflying </blue_name>
        <blue_text> 一个简单的查询 </blue_text>
        <blue_time> 2002-1-11   17:35:33 </blue_time>
        <blue_class> XML专题 </blue_class>
    </team>
    <team>
        <blue_ID> 2 </blue_ID>
        <blue_name> flyingbird </blue_name>
        <blue_text> 嫁给你,是要你疼的 </blue_text>
        <blue_time> 2001-09-06   12:45:51 </blue_time>
        <blue_class> 灌水精华 </blue_class>
    </team>
    <team>
        <blue_ID> 3 </blue_ID>
        <blue_name> 苛子 </blue_name>
        <blue_text> 正则表达式在UBB论坛中的应用 </blue_text>
        <blue_time> 2001-11-23   21:02:16 </blue_time>
        <blue_class> Web   编程精华 </blue_class>
    </team>
    <team>
        <blue_ID> 4 </blue_ID>
        <blue_name> 太乙郎 </blue_name>
        <blue_text> 年末经典分舵聚会完全手册   v0.1 </blue_text>
        <blue_time> 2000-12-08   10:22:48 </blue_time>
        <blue_class> 论坛灌水区 </blue_class>
    </team>
    <team>
        <blue_ID> 5 </blue_ID>
        <blue_name> mmkk </blue_name>
        <blue_text> Asp错误信息总汇 </blue_text>
        <blue_time> 2001-10-13   16:39:05 </blue_time>
        <blue_class> javascript脚本 </blue_class>
    </team>
</BlueIdea>  
 

search.xsl  
<?xml   version= "1.0 "   encoding= "gb2312 "   ?>
<xsl:stylesheet   xmlns:xsl= "http://www.w3.org/TR/WD-xsl ">
<xsl:template   match= "/ ">
<html>
<head>
<title>   XML卷之实战锦囊(2):动态查询 </title>
<style>
body,BlueIdea,team,blue_ID,blue_name,blue_text,blue_time,blue_class{   font:   12px   "宋体 ",   "Arial ",   "Times   New   Roman ";   }  
table   {   font-size:   12px;   border:   0px   double;   border-color:   #99CC99   #99CC99   #CCCCCC   #CCCCCC;   cellpadding:3;cellspacing:3;   bgcolor:#eeeeee;   text-decoration:   blink}  
span   {   font-size:   12px;   color:   red;   }
</style>
<script>
function   searchtext(x)  
{


stylesheet=document.XSLDocument;
source=document.XMLDocument;
sortField=document.XSLDocument.selectNodes( "//@select ");
if   (x!= " ")
{
sortField[1].value= "team[blue_ID= ' "+x+ " '] ";
Layer1.innerHTML=source.documentElement.transformNode(stylesheet);
}
else   {alert( "请输入筛选条件! ");}  
}
</script>
</head>
<body>
<p   align= "center "> <span> XML卷之实战锦囊(2):动态查询 </span> </p>
<div   id= "Layer1 "   name= "Layer1 ">
<xsl:apply-templates   select= "BlueIdea "   />
</div>
<hr   size= "1 "   width= "500 "   />
<table   align= "center "   cellpadding= "0 "   cellspacing= "0 "   border= "0 "   >
<tr>
<td>
<span   > 请输入筛选条件   :   </span>
blue_ID=   <input   type= "text "   name= "searchtext "   size= "1 "   maxlength= "1 "   />
<input   type= "button "   class= "button "   onClick= "searchtext(document.all.searchtext.value) "   value= "Search "   name= "button "   />
</td>
</tr>
</table>
</body>
</html>
</xsl:template>
<xsl:template   match= "BlueIdea ">
<table   width= "500 "   border= "1 "   align= "center "   cellpadding= "1 "   cellspacing= "1 "   bordercolordark= "#ffffff "   bordercolorlight= "#ADAAAD ">
<tr   bgcolor= "#FFCC99 "   align= "center ">
<td> 编号 </td>
<td> 姓名 </td>
<td> 主题 </td>
<td> 发表时间 </td>
<td> 归类 </td>
</tr>
<xsl:apply-templates   select= "team "   order-by= "blue_ID "/>
</table>
</xsl:template>
<xsl:template   match= "team ">
<tr   align= "center ">
<xsl:apply-templates   select= "blue_ID "   />
<xsl:apply-templates   select= "blue_name "   />
<xsl:apply-templates   select= "blue_text "   />
<xsl:apply-templates   select= "blue_time "   />
<xsl:apply-templates   select= "blue_class "   />
</tr>
</xsl:template>
<xsl:template   match= "blue_ID ">
<td   bgcolor= "#eeeeee ">
<xsl:value-of   />
</td>
</xsl:template>
<xsl:template   match= "blue_name ">
<td>
<xsl:value-of   />
</td>
</xsl:template>
<xsl:template   match= "blue_text ">
<td>
<xsl:value-of   />
</td>
</xsl:template>
<xsl:template   match= "blue_time ">
<td>
<xsl:value-of   />
</td>
</xsl:template>
<xsl:template   match= "blue_class ">
<td>
<xsl:value-of   />
</td>
</xsl:template>
</xsl:stylesheet>  


------解决方案--------------------


<html>
<head>
<script
type= "text/javascript "
for= "window "
event= "onload ">
var xmlDoc=new ActiveXObject( "Microsoft.XMLDOM ")
xmlDoc.async= "false "
xmlDoc.load( "note.xml ")
nodes=xmlDoc.documentElement.childNodes
a1.innerText=nodes.item(0).text
a2.innerText=nodes.item(1).text
a3.innerText=nodes.item(2).text
</script>
</head>
<body bgcolor= "yellow ">
<h1> W3Schools Internal Note </h1>
<b> To: </b>
<span id= "a1 "> </span>
<br />
<b> From: </b>
<span id= "a2 "> </span>
<hr />
<b> <span id= "a3 "> </span> </b>
<hr />
<span id= "a4 "> </span>
</body>
</html>

===========================
note.xml

<?xml version= "1.0 " encoding= "gb2312 " ?>
- <note>
<from> karso </from>
<to> mm </to>
<message> 好人 </message>
</note>

也许对你有帮助
[解决办法]
search.xls <?xml version= "1.0 " encoding= "gb2312 " ?> <xsl:stylesheet version= "1.0 " xmlns:xsl= "http://www.w3.org/1999/XSL/Transform "> <xsl:template match= "/ "> <html> <head> <title> XML卷之实战锦囊(2):动态查询 </title> <style> body,BlueIdea,team,blue_ID,blue_name,blue_text,blue_time,blue_class{ font: 12px "宋体 ", "Arial ", "Times New Roman "; } table { font-size: 12px; border: 0px double; border-color: #99CC99 #99CC99 #CCCCCC #CCCCCC; cellpadding:3;cellspacing:3; bgcolor:#eeeeee; text-decoration: blink} span { font-size: 12px; color: red; } </style> <script> function searchtext(x) { stylesheet=document.XSLDocument;source=document.XMLDocument;sortField=document.XSLDocument.selectNodes( "//@select "); if (x!= " "){ sortField[1].value= "team[./blue_ID[contains(., ' "+x+ " ')]] "; Layer1.innerHTML=source.documentElement.transformNode(stylesheet);}else {alert( "请输入筛选条件! ");} } </script> </head> <body> <p align= "center "> <span> XML卷之实战锦囊(2):动态查询 </span> </p> <div id= "Layer1 " name= "Layer1 "> <xsl:apply-templates select= "BlueIdea " /> </div> <hr size= "1 " width= "500 " /> <table align= "center " cellpadding= "0 " cellspacing= "0 " border= "0 " > <tr> <td> <span > 请输入筛选条件 : </span> blue_ID= <input type= "text " name= "searchtext " size= "1 " maxlength= "1 " /> <input type= "button " class= "button " onClick= "searchtext(document.all.searchtext.value) " value= "Search " name= "button " /> </td> </tr> </table> </body> </html> </xsl:template> <xsl:template match= "BlueIdea "> <table width= "500 " border= "1 " align= "center " cellpadding= "1 " cellspacing= "1 " bordercolordark= "#ffffff " bordercolorlight= "#ADAAAD "> <tr bgcolor= "#FFCC99 " align= "center "> <td> 编号 </td> <td> 姓名 </td> <td> 主题 </td> <td> 发表时间 </td> <td> 归类 </td> </tr> <xsl:for-each select= "team " > <TR> <TD> <xsl:value-of select= "blue_ID " > </xsl:value-of> </TD> <TD> <xsl:value-of select= "blue_name "> </xsl:value-of> </TD> <TD> <xsl:value-of select= "blue_text "> </xsl:value-of> </TD> <TD> <xsl:value-of select= "blue_time "> </xsl:value-of> </TD> <TD> <xsl:value-of select= "blue_class "> </xsl:value-of> </TD> </TR> </xsl:for-each> </table> </xsl:template> </xsl:stylesheet>

热点排行