RE: [xsl] forum threads sorting

Subject: RE: [xsl] forum threads sorting
From: "McNally, David" <David.McNally@xxxxxxxxxx>
Date: Tue, 26 Feb 2002 13:57:22 -0500
I'm not entirely confident in my logic, but as far as I can tell, this
works:

<xsl:template match="/">
	<xsl:for-each select="//aaa[not(aaa)]">
		<xsl:sort select="translate(@vl,'-','')"
order="descending"/>
		<xsl:variable name="thisnode" select="generate-id(.)"/>
		<xsl:variable name="thisdate"
select="translate(substring-before(@vl,' '),'-','')"/>
		<xsl:if test="not(ancestor::aaa[last()]//aaa[not(aaa) and
generate-id(.) != $thisnode]/@vl[translate(substring-before(.,' '),'-','') >
$thisdate])">
			<xsl:apply-templates
select="ancestor-or-self::aaa[last()]"/>
		</xsl:if>
	</xsl:for-each>
</xsl:template>

Basically I'm iterating through the leaf nodes in date order, testing each
one to see if it has the latest date within its subtree.  If so - process
it's ancestor aaa element.  I'm only looking at the date, but I guess some
more string handling could be added to deal with the time as well.

David.
--
David McNally            Moody's Investors Service
Software Engineer        99 Church St, NY NY 10007 
David.McNally@xxxxxxxxxx            (212) 553-7475 


> -----Original Message-----
> From: Oleg Tkachenko [mailto:olegt@xxxxxxxxxxxxx]
> Sent: Tuesday, February 26, 2002 9:54 AM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] forum threads sorting
> 
> 
> Hello!
> 
> Here is a sorting problem I cannot manage:
> 
> input xml represents forum threads
> 
> <root>
> 	<aaa vl="2001-12-02 13:56">
> 		<aaa vl="2002-01-02 12:32">
> 			<aaa vl="2002-01-03 14:43" />
> 		</aaa>
> 		<aaa vl="2002-02-01 13:43" />
> 	</aaa>
> 	<aaa vl="2002-01-03 14:54" />
> 	<aaa vl="2002-02-01 10:44">
> 		<aaa vl="2002-02-01 10:45" />
> 	</aaa>
> </root>
> 
> and stylesheet have to sort threads (root/aaa elements) by 
> last message 
> date (taking into account vl attributes in descendants elements).
> 
> I can sort by root/aaa dates, but I can't consider descendant messages
> 
> <xsl:sort select="translate(@vl, '-, ','')" />
> 
> PS. I'm aware of xslt2 and saxon solutions, but unfortunately I need 
> pure xslt1 one.
> 
> -- 
> Oleg Tkachenko
> Multiconn International, Israel
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 


---------------------------------------

The information contained in this e-mail message, and any attachment thereto, is confidential and may not be disclosed without our express permission.  If you are not the intended recipient or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that you have received this message in error and that any review, dissemination, distribution or copying of this message, or any attachment thereto, in whole or in part, is strictly prohibited.  If you have received this message in error, please immediately notify us by telephone, fax or e-mail and delete the message and all of its attachments.  Thank you.

Every effort is made to keep our network free from viruses.  You should, however, review this e-mail message, as well as any attachment thereto, for viruses.  We take no responsibility and have no liability for any computer virus which may be transferred via this e-mail message.


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


Current Thread