This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: Urgent Help Needed in XSLT
- From: "Kong, Yan" <KongY at corning dot com>
- To: "'xsl-list at lists dot mulberrytech dot com'" <xsl-list at lists dot mulberrytech dot com>
- Date: Mon, 23 Sep 2002 10:57:24 -0400
- Subject: RE: [xsl] Urgent Help Needed in XSLT
- Reply-to: xsl-list at lists dot mulberrytech dot com
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@marrowsoft.com]
> Reply To: xsl-list@lists.mulberrytech.com
> Sent: Friday, September 20, 2002 6:16 PM
> To: xsl-list@lists.mulberrytech.com
> Subject: RE: [xsl] 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() < 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