RE: [xsl] sorting by date

Subject: RE: [xsl] sorting by date
From: "Daniel Newman" <daniel.newman@xxxxxxxxxxx>
Date: Tue, 24 Jul 2001 15:40:43 +0100
Urrrggghhh, it's obviously been a long week (yes, I know it's only Tuesday);

I have no idea what you're saying here :-(

My first XSL, which is working but unsorted, looks like this:

<xsl:template name="GetTableData">
	<xsl:call-template name="ShowRunningBalance">
		<xsl:with-param name="ThisRecord" select="1" />
		<xsl:with-param name="MaxRecord"
select="RetrieveTransactionHistory2RSResponse/NoOfItems" />
		<xsl:with-param name="CurrentBalance"
select="HoldingInformation2Response/Items/Item[class_code =
$ClassCode]/Holding" />
	</xsl:call-template>
</xsl:template>

<xsl:template name="ShowRunningBalance">
	<xsl:param name="ThisRecord" />
	<xsl:param name="MaxRecord" />
	<xsl:param name="CurrentBalance" />
	<xsl:variable name="TestValue"
select="RetrieveTransactionHistory2RSResponse/Items/Item[position()=$ThisRec
ord]/UnitsTraded" />
	<xsl:variable name="UnitsTraded">
		<xsl:choose>
			<xsl:when test="$TestValue != 0">
				<xsl:value-of select="$TestValue" />
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of
select="RetrieveTransactionHistory2RSResponse/Items/Item[position()=$ThisRec
ord]/MoneyTrade" />
			</xsl:otherwise>
		</xsl:choose>
	</xsl:variable>
	<xsl:choose>
		<xsl:when test="$ThisRecord &lt;= $MaxRecord">
			<tr valign="top">
			<xsl:call-template name="GenerateRowColor">
				<xsl:with-param name="Index" select="$ThisRecord + 1" />
			</xsl:call-template>
				<td width="10%">
				<xsl:variable name="ThisDate"
select="RetrieveTransactionHistory2RSResponse/Items/Item[position()=$ThisRec
ord]/Date" />
				<xsl:value-of select="concat(substring($ThisDate, 1, 2), '/',
substring($ThisDate, 3, 2), '/', substring($ThisDate, 5))" />
				</td>
				<td width="50%" nowrap="nowrap">
				<xsl:value-of
select="RetrieveTransactionHistory2RSResponse/Items/Item[position()=$ThisRec
ord]/Description" />
				</td>
				<td align="right" width="15%">
				<xsl:call-template name="PlusOrMinus">
					<xsl:with-param name="ThisNumber" select="$UnitsTraded" />
				</xsl:call-template>
				<xsl:value-of select="format-number($UnitsTraded, '#,##0')" />
				</td>
				<td align="right" width="15%">
				<xsl:call-template name="PlusOrMinus">
					<xsl:with-param name="ThisNumber" select="$CurrentBalance" />
				</xsl:call-template>
				<xsl:value-of select="format-number($CurrentBalance, '#,##0')" />
				</td>
				<td bgcolor="{$DisplayCell}">
					<img src="/images/shim.gif" border="0" width="20" height="20" />
				</td>
				<td bgcolor="{$AmendCell}">
					<img src="/images/shim.gif" border="0" width="20" height="20" />
				</td>
			</tr>
			<xsl:call-template name="ShowRunningBalance">
				<xsl:with-param name="ThisRecord" select="$ThisRecord + 1" />
				<xsl:with-param name="MaxRecord" select="$MaxRecord" />
				<xsl:with-param name="CurrentBalance" select="$CurrentBalance -
$UnitsTraded" />
			</xsl:call-template>
		</xsl:when>
	</xsl:choose>
</xsl:template>

So where, and how, do i include your xsl:sort tag?

and here it is in case you've all forgotten:

<xsl:sort
select="concat(substring(Date,5,4),substring(Date,3,2),substring(Date,1,2))"
/>


Daniel.

-----Original Message-----
From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of David
Carlisle
Sent: 24 July 2001 15:09
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] sorting by date



In the snippet you posted earlier there was only one
RetrieveTransactionHistory2RSResponse

so
<xsl:apply-templates select="RetrieveTransactionHistory2RSResponse">
	<xsl:sort (anything)

is sorting a list of length 1, so nor sort key is going to change
anything.


If you want to sort the Item elements you need to select those and then
sort using the path I suggested using substring(Date....

David

_____________________________________________________________________
This message has been checked for all known viruses by Star Internet
delivered through the MessageLabs Virus Scanning Service. For further
information visit http://www.star.net.uk/stats.asp or alternatively call
Star Internet for details on the Virus Scanning Service.

 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