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

Re: "Group by" question

Subject: Re: "Group by" question
From: Raffaele Sena <raff@xxxxxxxxxxxx>
Date: Mon, 22 Mar 2004 09:35:04 -0800
xsl group by
You should be able to "loop" on "doc", sorted by "address" and generate an "address" element for the first "doc" with a certain address. Not very efficient, but it should do the job:

<xsl:template match="/docs">
<xsl:for-each select="doc">
<xsl:sort select="@address" data-type="text"/>
<xsl:variable name="this-address" select="@address"/>
<xsl:if test="position()=1 or preceding-sibling::doc/@address != $this-address">
<xsl:address val="{$this-address}">
<xsl:apply-templates select="../doc[@address = $this-address}"/>
</xsl:address>
</xsl:if>
</xsl:for-each>
</xsl:template>


<xsl:template match="doc">
  <!-- process doc -->
</xsl:template>

Regards,

Raffaele Sena

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

On Monday, March 22, 2004, at 08:58 AM, Hilder Sousa wrote:

Hi :)

I would like to kwonw how can I do a "group by".. I explain:
Imagine i have the next xml:
<docs>
	<doc id="doc1" address="av. A1">
		<pages>
			<page>...</page>
			<page>...</page>
		</pages>
	<doc>
	<doc id="doc2" address="av. A2">
		<pages>
			<page>...</page>
		</pages>
	<doc>
	<doc id="doc3" address="av. A1">
		<pages>
			<page>...</page>
			<page>...</page>
			<page>...</page>
		</pages>
	<doc>
</docs>

I need a xsl to "group by" the address. Like this:

<address val="av. A1">
	<doc id="doc1">
		...
	</doc>
	<doc id="doc3">
		...
	</doc>
</address>
<address val="av. A2">
	<doc id="doc2">
		...
	</doc>
</address>

Tks in advanced :)

Hilder Sousa

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.