-- 作者:wtoxiao
-- 发布时间:2/4/2008 10:40:00 AM
-- 将XML解析成一棵树,显示在页面中,非常着急。
以下是用于解析xml的xsl,可以将xml显示成一棵树。有一个问题始终解决不了,非常着急,想请教大家。 我想在显示的节点上加一个联接,提交到服务器的一个jsp,参数是当前节点的名字(见xsl红色黑体部分),不知道该怎么写? 。 感谢各位高人。 <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" indent="no" encoding="utf-8" /> <!--HTML Template--> <xsl:template match="/"> <html version="1.1" xmlns="http://www.w3.org/1999/xhtml"> <head> <title> <xsl:value-of select="comment()" /> </title> <style type="text/css"> .xml { font-family: Tahoma; font-size: 9pt; color: blue; } .xml div { margin-left: 16px; } .xmlAttribute { color: red; } .xmlComment { color: green; } .xmlName { color: maroon; } .xmlPI { color: gray; } .xmlText { color: black; } </style> <script type="text/javascript"> function collapse(a) { var div = a.nextSibling.nextSibling.nextSibling; if(div.style.display == "") { div.style.display = "none"; a.src = "images/Lplus.png"; } else { div.style.display = ""; a.src = "images/Lminus.png"; } } function DoClick(b){ alert("999"); alert(document.nodeName.value); opener.Refresh(); CloseMe(); window.focus(); } </script> </head> <body class="xml"> <span class="xmlPI"> <img src="images/sm_star.gif" border="0" /> <ROOT> </span> <br /> <xsl:apply-templates /> </body> </html> </xsl:template> <!--Attribute Template--> <xsl:template match="@*"> <xsl:text> </xsl:text> <span class="xmlAttribute"> <xsl:value-of select="name()" /> </span> <xsl:text> =" </xsl:text> <span class="xmlText"> <xsl:value-of select="." /> </span> <xsl:text> " </xsl:text> </xsl:template> <!--Processing Instruction Template--> <xsl:template match="processing-instruction()"> <span class="xmlPI"> <xsl:text> <? </xsl:text> <xsl:value-of select="name()" /> <xsl:text> </xsl:text> <xsl:value-of select="." /> <xsl:text> ?> </xsl:text> </span> <br /> </xsl:template> <!--Comment Template--> <xsl:template match="comment()"> <span class="xmlComment"> <xsl:text> <!-- </xsl:text> <xsl:value-of select="." /> <xsl:text> --> </xsl:text> </span> <br /> </xsl:template> <!--Text Template--> <xsl:template match="text()"> <xsl:if test="text() != ''"> <span class="xmlText"> <xsl:value-of select="." /> </span> <br /> </xsl:if> </xsl:template> <!--Empty Element Template--> <xsl:template match="*"> <img src="images/file.png" border="0" /> <xsl:text> < </xsl:text> <span class="xmlName"> <xsl:value-of select="name()" /> </span> <xsl:apply-templates select="@*" /> <xsl:text> /> </xsl:text> <br /> </xsl:template> <!--Text Element Template--> <xsl:template match="*[text()]"> <img src="images/file.png" border="0" /> <xsl:text> </xsl:text> <span class="xmlName"> <xsl:value-of select="name()" /> </span> <xsl:apply-templates select="@*" /> <xsl:text> > </xsl:text> <span class="xmlText"> <xsl:value-of select="." /> </span> <xsl:text> </ </xsl:text> <span class="xmlName"> <xsl:value-of select="name()" /> </span> <xsl:text> > </xsl:text> <br /> </xsl:template> <!--Node Element Template--> <xsl:template match="*[*]"> <img src="images/Lminus.png" border="0" onclick="collapse(this)" /> <img src="images/foldericon.png" border="0" /> [color=#FF0000] <a href="/showXML.jsp?nodeName=" class="f11du"> [/color] <xsl:text> < </xsl:text> <span class="xmlName"> <xsl:value-of select="name()" /> </span> <xsl:apply-templates select="@*" /> <xsl:text> > </xsl:text> </a> <div> <xsl:apply-templates /> </div> <xsl:text> </ </xsl:text> <span class="xmlName"> <xsl:value-of select="name()" /> </span> <xsl:text> > </xsl:text> <br /> </xsl:template> </xsl:stylesheet>
|