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

RE: forum threads sorting

Subject: RE: forum threads sorting
From: "McNally, David" <David.McNally@xxxxxxxxxx>
Date: Wed, 27 Feb 2002 10:53:15 -0500
david mcnally
Erm - I realised that the approach I posted would output duplicate forum
threads if there were two messages in the thread that had exactly the same
date, and that date was the latest date within the thread.  Adding the time
handling in the date comparison probably makes this very unlikely, but just
to be safe, here's the corrected version (which does handle time):


<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="thisvl" select="@vl"/>
		<xsl:variable name="thisdate"
select="concat(translate(substring-before($thisvl,' '),
'-',''),translate(substring-after($thisvl,' '),':',''))"/>
		<xsl:choose>
			<xsl:when
test="not(ancestor::aaa[last()]//aaa[not(aaa) and generate-id(.) !=
$thisnode]/@vl[concat(translate(substring-before(.,'
'),'-',''),translate(substring-after(.,' '), ':','')) >= $thisdate])">
				<xsl:apply-templates
select="ancestor-or-self::aaa[last()]"/>
			</xsl:when>
			<xsl:when test="ancestor::aaa[last()]//aaa[not(aaa)
and generate-id(.) != $thisnode]/@vl[concat(translate(substring-before(.,'
'),'-',''),translate(substring-after(.,' '),':','')) = $thisdate]">
				<xsl:if
test="count(ancestor::aaa[last()]//aaa[@vl = $thisvl][1] | current()) = 1">
					<xsl:apply-templates
select="ancestor-or-self::aaa[last()]"/>
				</xsl:if>
			</xsl:when>
		</xsl:choose>		
	</xsl:for-each>
</xsl:template>

Who said perl was hard to read?

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


> -----Original Message-----
> From: McNally, David 
> Sent: Tuesday, February 26, 2002 1:57 PM
> To: 'xsl-list@xxxxxxxxxxxxxxxxxxxxxx'
> Subject: RE:  forum threads sorting
> 
> 
> 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 
> 
> 


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

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

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.