Re: [xsl] XSL Grouping

Subject: Re: [xsl] XSL Grouping
From: "David B. Bitton" <david@xxxxxxxxxxxxxx>
Date: Mon, 12 Nov 2001 14:59:08 -0500
Don'w worry, I had an extra for-each.  All is great now.  Thanks alot!  Also, Jeni, do you ever lecture on the
subject in or around the New York area?

On Mon, Nov 12, 2001 at 02:09:13PM -0500, David B. Bitton wrote:
> I have implemented this:
> 
> 			<xsl:for-each select="Transaction[count(. | key('TransactionsByStatus', Status)[1]) =
> 1]">
> 				<xsl:sort select="Status"/>
> 				<tr class="Report">
> 					<td colspan="8">
> 						<b>
> 						<xsl:choose>
> 							<xsl:when test="Status='C'">
> 								<xsl:value-of
> select="count(key('TransactionsByStatus', Status))"/><xsl:text> confirmed transaction</xsl:text>
> 							</xsl:when>
> 							<xsl:when test="Status='A'">
> 								<xsl:value-of
> select="count(key('TransactionsByStatus', Status))"/><xsl:text> accepted, awaiting confirmation</xsl:text>
> 							</xsl:when>
> 							<xsl:when test="Status='R'">
> 								<xsl:value-of
> select="count(key('TransactionsByStatus', Status))"/><xsl:text> rejected</xsl:text>
> 							</xsl:when>
> 							<xsl:when test="Status='Y' or Status = 'N'">
> 								<xsl:value-of
> select="count(key('TransactionsByStatus', Status))"/><xsl:text> transaction awaiting submission</xsl:text> 
> 							</xsl:when>			
> 							<xsl:when test="Status='2' or Status='3' or Status='4'
> or Status='5' or Status='6' or Status='7' or Status='8' or Status='9'">
> 								<xsl:value-of
> select="count(key('TransactionsByStatus', Status))"/><xsl:text> transaction awaiting </xsl:text> <xsl:value-of
> select="Status" /><xsl:text> more approvals</xsl:text>
> 							</xsl:when>
> 						</xsl:choose>
> 						</b>
> 					</td>
> 				</tr>
> 				<xsl:for-each select="key('TransactionsByStatus', Status)">
> 					<xsl:sort select="*[local-name() = string($sortby)]"
> data-type="{$datatype}" order="{$order}"/>
> 					
> 					<xsl:for-each select="key('TransactionsByStatus', Status)
> 
> [generate-id() =
> 
> generate-id(key('TransactionsByStatusAndCurrencyCode',
> 
> concat(Status, '::', CurrencyCode))[1])]">
> 												
> 							<tr><td class="ReportD" colspan="8"><xsl:value-of
> select="CurrencyCode"/></td></tr>
> 							
> 							<xsl:for-each
> select="key('TransactionsByStatusAndCurrencyCode',
> 
> concat(Status, '::', CurrencyCode))">
> 
> 
> and I'm getting all transaction repeated for all currencycode, so if there are three transactions in the group, I
> get three under each unique currencycode, hrm. :)
> 
> On Mon, Nov 12, 2001 at 05:56:22PM +0000, Jeni Tennison wrote:
> > Hi David,
> > 
> > > This is one transaction. First we group by Status, no prob. Now I
> > > want to group by CurrencyCode within each Status group. I'm just not
> > > seeming to get the right combo of xsl:key and key() XPath in the sub
> > > for-each. Can someone lend a hand? Tx :)
> > 
> > Sure. The key that you use for the second level group has to index
> > each Transaction by a combination of its Status and its CurrencyCode.
> > The easiest way to get such a combination value is using the concat()
> > function, so try:
> > 
> > <xsl:key name="TransactionsByStatusAndCurrencyCode"
> >          match="Transaction"
> >          use="concat(Status, '::', CurrencyCode)" />
> > 
> > [Obviously you don't have to use such a long name, I'm just doing so
> > to make things clear.]
> > 
> > At the point where currently you're retrieving all the Transaction
> > elements with a particular status, you need to filter that set to
> > include only those that have that Status *and* have a unique
> > CurrencyCode, with something like:
> > 
> >   key('TransactionsByStatus', $status)
> >     [generate-id() =
> >      generate-id(key('TransactionsByStatusAndCurrencyCode',
> >                      concat($status, '::', CurrencyCode))[1])]
> > 
> > And once you're processing such a Transaction, you can get all the
> > other Transaction elements with the same Status and CurrencyCode with:
> > 
> >   key('TransactionsByStatusAndCurrencyCode'
> >       concat(Status, '::', CurrencyCode))
> > 
> > I hope that helps,
> > 
> > Jeni
> > 
> > ---
> > Jeni Tennison
> > http://www.jenitennison.com/
> > 
> > 
> >  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 
> -- 
> 
> David B. Bitton
> david@xxxxxxxxxxxxxx
> 
> Diversa ab illis virtute valemus.



-- 

David B. Bitton
david@xxxxxxxxxxxxxx

Diversa ab illis virtute valemus.

Attachment: pgp00003.pgp
Description: PGP signature

Current Thread