以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 XSL/XSLT/XSL-FO/CSS 』  (http://bbs.xml.org.cn/list.asp?boardid=8)
----  求助: 关于xsl的问题!  (http://bbs.xml.org.cn/dispbbs.asp?boardid=8&rootid=&id=50054)


--  作者:zhu_ruixian
--  发布时间:7/16/2007 8:24:00 PM

--  求助: 关于xsl的问题!
book.xml如下:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="book.xsl" type="text/xsl"?>
<Library>
 <Books id="bookid">
   <Book description="" name="book1" title="title">
      <Result result="2"/>
   </Book>
   <Book description="" name="book2" title="title">
      <Result result="2"/>
   </Book>
   <Book description="" name="book1" title="title">
      <Result result="2"/>
   </Book>
   <Book description="" name="book3" title="title">
      <Result result="4"/>
   </Book>
   <Book description="" name="book4" title="title">
      <Result result="1"/>
   </Book>
 </Books>   
</Library>

book.xsl如下:
<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="/Library">
  <html>
   <head>
    <title>Book Information</title>
   </head>
   <h1>Book Information</h1>
   <xsl:for-each select="Books">
   <table border ="1" width="100%">     
   <tr><td align="center">
   <table border ="1" width="100%">
     <tr>
      <td colSpan="2" align="center"><h3>Sets Name:<font color="#FF0000"><xsl:value-of select="@id" /></font></h3></td>
     </tr>
     <tr>
      <td colSpan="2" align="center"><h3>Books Number:
        <xsl:value-of select="count(Book/Result[@result='2'])"/>
      </h3></td>
     </tr>
     <tr>
      <td align="center">Name</td>
      <td>Results</td>
     </tr>
      <xsl:for-each select="*">
       <xsl:variable name="result" select="Result/@result"/>
       <xsl:if test="contains($result,'2')">
        <tr>
         <td>
          <xsl:value-of select="@name" />
         </td>
         <td>
          <xsl:value-of select="Result/@result" />
         </td>
        </tr>
       </xsl:if>
      </xsl:for-each>
     <tr><td colSpan="2">
    <xsl:for-each select="*">
    <xsl:variable name="result" select="Result/@result"/>
    <xsl:if test="contains($result,'2')">
     <font color="#FF0000"><xsl:value-of select="@name" /><p/> </font>  
    </xsl:if>
    </xsl:for-each>
     </td></tr>    
    </table>
    </td>
     </tr>
  </table>   
   </xsl:for-each>
  </html>
</xsl:template>
</xsl:stylesheet>

现在的输出结果为:

Book Information
Sets Name:bookid
Books Number: 3
Name Results
book1 2 
book2 2 
book1 2 

book1
book2
book1
我现在想让
book1
book2
book1  不出现重复的 ,该怎么筛选出来? 就是输出如下:
Book Information
Sets Name:bookid
Books Number: 3
Name Results
book1 2 
book2 2 
book1 2 

book1
book2

就是选出result=2的元素,输出他们父亲的名字,如果名字有重复的,只输出一个即可。谢谢!


--  作者:hexun831012
--  发布时间:7/17/2007 10:11:00 AM

--  
版主也求助阿,想实现聚合,对xsl来说很难
--  作者:Qr
--  发布时间:7/17/2007 5:14:00 PM

--  
以下是引用hexun831012在2007-7-17 10:11:00的发言:
版主也求助阿,想实现聚合,对xsl来说很难


版主就不能求助了?版主也是普通人啊,都是用脑子来想问题的!难怪偶发的求助贴只有看贴的,没有回贴的

看看是不是你想要的:
    <xsl:if test="contains($result,'2') and not(preceding-sibling::*/@name=@name)">
     <font color="#FF0000"><xsl:value-of select="@name" /><p/> </font>  
    </xsl:if>

用你的代码来测试就是你想要的结果,希望是对的


--  作者:zhu_ruixian
--  发布时间:7/17/2007 11:20:00 PM

--  谢谢Qr!
可以work,谢谢Qr!  你对xsl这么熟悉,是看的那本书,能推荐一下吗?

  
以下是引用hexun831012在2007-7-17 10:11:00的发言:
版主也求助阿,想实现聚合,对xsl来说很难


知之为之知之 不知为不知。  呵呵


--  作者:Qr
--  发布时间:7/18/2007 8:49:00 AM

--  
偶只有一本《XSLT程序员开发手册》,名字好象是这个仅当新华字典用。其它都是在这里学来的。

纠正一下,前面所用的preceding-sibling::*属XPath,并非XSL。补一下这方面的知识,你写XSL会更顺手的。


--  作者:zhu_ruixian
--  发布时间:7/19/2007 10:23:00 PM

--  
XSLT程序员开发手册   http://www.china-pub.com/  居然没有  faint!
--  作者:Qr
--  发布时间:7/20/2007 11:59:00 AM

--  
记错了,应该是《XSLT开发人员指南》,比较简单,适合入门用。http://www.china-pub.com缺货。

偶现在也正在寻找适合自己用的XSLT书籍。发现好的推荐一下 :-)


--  作者:hexun831012
--  发布时间:7/20/2007 12:55:00 PM

--  
还有《XSL高级编成》,但我买了一本发现比较过时,掏宝还有一本
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
78.125ms