This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: forum threads sorting


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@Moodys.com            (212) 553-7475 


> -----Original Message-----
> From: McNally, David 
> Sent: Tuesday, February 26, 2002 1:57 PM
> To: 'xsl-list@lists.mulberrytech.com'
> Subject: RE: [xsl] 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@Moodys.com            (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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]