-- 作者:dongle2001
-- 发布时间:10/29/2010 11:59:00 AM
-- xlst的compare函数如何传入参数?
xml文本如下: <?xml version="1.0" encoding="UTF-8"?> <response> <lst name="responseHeader"> <int name="status">0</int> <int name="QTime">282</int> <lst name="params"> <str name="explainOther"/> <str name="indent">on</str> <str name="hl.fl"/> <str name="wt">standard</str> <str name="hl">on</str> <str name="version">2.2</str> <str name="rows">20</str> <str name="fl">*,score</str> <str name="start">0</str> <str name="q">汽车</str> <str name="qt">standard</str> <str name="fq"/> </lst> </lst> <result name="response" numFound="1529" start="0" maxScore="1.8097835"> <doc> <float name="score">1.8097835</float> <str name="DES">The present invention relates to an automobile garage which is a layer type automobile garage with the advantages of small occupation area and short time for storing and taking automobiles. A large layer type automobile garage can store ten of thousands of automobiles.</str> <str name="SRC">本汽车库,是一种层式汽车库,占地面积小,存取汽车时间短。大型的层式汽车库,可存放数万辆汽车。</str> <str name="id">90101608</str> </doc> </result> <lst name="highlighting"> <lst name="90101608"> <arr name="SRC"> <str>本<em>汽车</em>库,是一种层式<em>汽车</em>库,占地面积小,存取<em>汽车</em>时间短。大型的层式<em>汽车</em>库,可存放数万辆<em>汽车</em>。</str> </arr> </lst> </lst> </response> <doc>和<lst name="90101608">都是多个. 我想实现的网页效果如下: 第一行显示lst[@name='highlighting']/lst的内容 第二行显示result/doc/str[@name='id']节点文本于lst节点的name属性值相等的str节点. 如此这个循环显示所有的信息. 这个效果应该如何实现? 下面是我写的xsl 文件,无法通过java的编译. 提示:错误:“line 39: 分析 XPath 表达式“result/doc/str[@name='id' and compare(., {$id}) = 0]”时出错。” <?xml version="1.0" encoding="UTF-8"?> <!-- Edited with XML Spy v2007 (http://www.altova.com) --> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>分级显示</title> <script type="text/javascript"> function display(y){$(y).style.display=($(y).style.display=="none")?"":"none";} function $(s){return document.getElementById(s);} </script> </head> <body> <table border="0"> <tr> <td>查询时间:</td> <td><xsl:value-of select="//int[@name='QTime']"/></td> <td>关键字:</td> <td><xsl:value-of select="//str[@name='q']"/></td> <td>结果个数:</td> <td><xsl:value-of select="//str[@name='rows']"/></td> </tr> </table> <xsl:apply-templates/> </body> </html> </xsl:template> <xsl:template match="response"> <table border="0" width="100%"> <xsl:for-each select="lst[@name='highlighting']/lst"> <xsl:variable name="id" select="@name"/> <tr width="100%"> <b><xsl:value-of select="$id"/> : </b><xsl:value-of select="arr/str"/> </tr> <table width="100%"> <tr> ID:<xsl:value-of select="result/doc/str[@name='id' and compare(., {$id}) = 0]"/> </tr> </table> </xsl:for-each> </table> </xsl:template> </xsl:stylesheet>
|