[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Urgent Help Needed in XSLT

Subject: RE: Urgent Help Needed in XSLT
From: "Kong, Yan" <KongY@xxxxxxxxxxx>
Date: Mon, 23 Sep 2002 10:57:24 -0400
ancestor or self xslt
Marrow,

I really appreciate your reply.  I think you have understood what I want.  I need to display the latest top 10 discussion topics in HTML which have either the latest reply or latest new topic.  

I'm a beginner of XSLT, just started to read Michael Kay's XSLT Programmer's Reference two weeks ago.  This is a totally different concept for me from other programming language.  I have one question regarding your codes:

	 <xsl:key name="kDistinctTopic" match="/livelink//llnode"
> use="ancestor-or-self::llnode[last()]/@name"/>
> 
My understand is that "descendant-or-self" should be used instead of "ancestor-or-self" as we need to get one lastest children or self llnode from the same topic.  If this is true, I also need to change the first "for-each":

>     <xsl:for-each select=".//llnode[generate-id() =
> generate-id(key('kDistinctTopic',ancestor-or-self::llnode[last()]/@name) 
> )]">
> 
Replace "ancestor-or-self" to "descendant-or-self", am I right?

Thanks a lot,
Yan

> ----------
> From: 	Marrow[SMTP:marrow@xxxxxxxxxxxxxx]
> Reply To: 	xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Sent: 	Friday, September 20, 2002 6:16 PM
> To: 	xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: 	RE:  Urgent Help Needed in XSLT
> 
> Hi Yan,
> 
> Do you mean something like Google groups does?
> 
> Try this (not sure if it does what you want)...
> 
> == XSL ====================================================
> <?xml version="1.0"?>
> <xsl:stylesheet version="1.0"
>  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> <xsl:output method="html" indent="yes"/>
> <xsl:key name="kDistinctTopic" match="/livelink//llnode"
> use="ancestor-or-self::llnode[last()]/@name"/>  (question 1)
> <xsl:template match="livelink">
>   <!-- create a list of (node ids) for each distinct topic -->
>   <!-- with the id of the latest message in that thread   -->
>   <xsl:variable name="sorted-topic-dates">
>     <!-- find the distinct topics -->
>     <xsl:for-each select=".//llnode[generate-id() =
> generate-id(key('kDistinctTopic',ancestor-or-self::llnode[last()]/@name)   (question 1)
> )]">
>       <!-- sort this and descendant children by their descending date
> -->
>       <xsl:for-each select="descendant-or-self::llnode">
>         <xsl:sort select="@created" order="descending"/>
>         <!-- output a reference to this node if it the latest in this
> 'thread' -->
>         <xsl:if test="position() = 1">
>           <xsl:text>|</xsl:text>
>           <xsl:value-of select="generate-id()"/>
>         </xsl:if>
>       </xsl:for-each>
>     </xsl:for-each>
>   </xsl:variable>
>   <html>
>     <body>
>       <table>
>         <!-- go through all nodes where they appear in the distinct
> topic dates variable -->
>         <xsl:for-each
> select=".//llnode[contains($sorted-topic-dates,concat('|',generate-id())
> )]">
>           <!-- sort them on date descending -->
>           <xsl:sort select="@created" order="descending"/>
>           <!-- only show the first 10 -->
>           <xsl:if test="position() &lt; 11">
>             <tr>
>               <td>
>                 <xsl:value-of
> select="ancestor-or-self::llnode[last()]/@name"/>
>               </td>
>               <td>
>                 <xsl:value-of select="@created"/>
>               </td>
>               <td>
>                 <xsl:choose>
>                   <xsl:when test="ancestor::llnode">
>                     <xsl:text> (Reply)</xsl:text>
>                   </xsl:when>
>                   <xsl:otherwise>
>                     <xsl:text> (New Topic)</xsl:text>
>                   </xsl:otherwise>
>                 </xsl:choose>
>               </td>
>             </tr>
>           </xsl:if>
>         </xsl:for-each>
>       </table>
>     </body>
>   </html>
> </xsl:template>
> </xsl:stylesheet>
> == end of XSL =============================================
> 
> Hope this helps
> Marrow 
> http://www.marrowsoft.com>  - home of Xselerator (XSLT IDE and debugger)
> http://www.topxml.com/Xselerator
> 
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread
  • Urgent Help Needed in XSLT
    • Kong, Yan - Fri, 20 Sep 2002 16:42:51 -0400 (EDT)
      • Marrow - Fri, 20 Sep 2002 18:13:59 -0400 (EDT)
      • <Possible follow-ups>
      • Kong, Yan - Mon, 23 Sep 2002 10:57:09 -0400 (EDT) <=
        • Marrow - Mon, 23 Sep 2002 11:29:19 -0400 (EDT)

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.