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: xslt 2 grouping


Using keys, I think this works - one key on the value (x, y) to do that
grouping, and then another with the value and attribute (x::a, x::b, etc) to
just get unique values.


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
	<xsl:output method="xml" version="1.0" encoding="UTF-8"
indent="yes"/>

<xsl:key name="mykey" match="el" use="normalize-space(.)"/>
<xsl:key name="mykey2" match="el"
use="concat(normalize-space(.),'::',@att)"/>

<xsl:template match="p">
<p>
	<xsl:apply-templates/>
</p>
</xsl:template>

<xsl:template match="el">
	<xsl:variable name="thiskey" select="normalize-space(.)"/>
	<xsl:choose>
		<xsl:when test="generate-id(.) =
generate-id(key('mykey',$thiskey)[1])">
			<el att="{$thiskey}">
				<xsl:for-each
select="key('mykey',$thiskey)">
					<xsl:variable name="thiskey2"
select="concat(normalize-space(.),'::',@att)"/>
					<xsl:choose>
						<xsl:when
test="generate-id(.) = generate-id(key('mykey2',$thiskey2)[1])">
							<xsl:value-of
select="@att"/>
							<xsl:text>
</xsl:text>
						</xsl:when>
					</xsl:choose>
				</xsl:for-each>
			</el>
		</xsl:when>
	</xsl:choose>
</xsl:template>


</xsl:stylesheet>

This:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="D:\Work\xsl\el_att.xsl"?>
<p>
	<el att="a">x</el>
	<el att="b">x</el>
	<el att="c">x</el>
	<el att="d">y</el>
	<el att="a">x</el>
	<el att="b">x</el>
	<el att="c">x</el>
	<el att="d">y</el>
	<el att="a">y</el>
</p>


Ends up as:

<p>
	<el att="x">a b c </el>
	<el att="y">d a </el>
</p>


Hope this helps,
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: DPawson@rnib.org.uk [mailto:DPawson@rnib.org.uk]
> Sent: Thursday, July 11, 2002 10:32 AM
> To: xsl-list@lists.mulberrytech.com
> Subject: [xsl] xslt 2 grouping
> 
> 
> With the following XML I'm trying to group and find uniques
> 
> <p>
> <el att='a'>x</el>
> <el att='b'>x</el>
> <el att='c'>x</el>
> <el att='d'>y</el>
> </p>
> I have about 1200 lines of this, so keys are out.
> 
> I want to find all the el elements with content 'a'
> which have *different* att attribute values,
> 
> to produce
> 
> <el name='x'>a b c </el>
> 
> I.e. list x, together with all the attributes att
> which are different.
> 
> I'm guessing its a good one for xslt 2, for-each and group-by,
> but I'm stumped on the syntax.
> 
> Any help appreciated,
> DaveP.
> 
> 
> 
> ************snip here************** 
> 
> - 
> 
> NOTICE: The information contained in this email and any 
> attachments is 
> confidential and may be legally privileged. If you are not the 
> intended recipient you are hereby notified that you must not use, 
> disclose, distribute, copy, print or rely on this email's content. If 
> you are not the intended recipient, please notify the sender 
> immediately and then delete the email and any attachments from your 
> system.
> 
> RNIB has made strenuous efforts to ensure that emails and any 
> attachments generated by its staff are free from viruses. However, it 
> cannot accept any responsibility for any viruses which are 
> transmitted. We therefore recommend you scan all attachments.
> 
> Please note that the statements and views expressed in this email 
> and any attachments are those of the author and do not necessarily 
> represent those of RNIB.
> 
> RNIB Registered Charity Number: 226227
> 
> Website: http://www.rnib.org.uk 
> 
>  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


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