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

RE: looping in xslt

Subject: RE: looping in xslt
From: "Kenny Akridge" <kenny@xxxxxxxxxxxxxxxxx>
Date: Thu, 29 Apr 2004 09:46:25 -0400
xsl looping
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:template match="/root">
		<xsl:element name="root">
<!-- loop through all rec/date nodes -->			
			<xsl:for-each select="rec/date">
<!-- if the context date/value node is the first in the tree with a given
value (and the set of all first nodes with the given value will be the set
of all unique nodes -->				
				<xsl:if test="generate-id(.) =
generate-id(/root/rec/date[value=current()/value])">
					<xsl:element name="rec">
						<xsl:element name="date">
							<xsl:element
name="value">
	
<xsl:value-of select="."/>
							</xsl:element>
						</xsl:element>
					</xsl:element>
				</xsl:if>
			</xsl:for-each>
		</xsl:element>
	</xsl:template>
</xsl:stylesheet>

-----Original Message-----
From: Joeri Belis [mailto:joeri.belis@xxxxxxxxxxxx] 
Sent: Thursday, April 29, 2004 9:12 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:  looping in xslt

I have a big xml file that comes out of a db ( + 3Mb ).
It contains a lot of date values. My xslt transformation needs to create a
new xml file
from this dump xml file and add lines for every date just ones.
So the file may contain 100 date values but only 10 different dates

( this example has 5 dates but only 3 different dates )
<?xml version="1.0"?>
<root>
  <rec>
    <date><value>010104</value></date>
  </rec>
  <rec>
    <date><value>010104</value></date>
    <date><value>020104</value></date>
  </rec>
  <rec>
    <date><value>020104</value></date>
    <date><value>030104</value></date>
  </rec>
</root>

to find these unique dates i use
<xsl:key name="mydates" match="date" use="value"/>
and to loop 3 times i use.
<xsl:for-each select="/root/rec/date[generate-id() =
generate-id(key('mydates',value)[1])]">

I need to loop multiple times so i repeat the "for-each" multiple times in
my code.
Is there a way to avoid this. It takes a long time to find all the unique
dates again and again.

Can i store a count
<xsl:for-each select="count(/root/rec/date[generate-id() =
generate-id(key('mydates',value)[1])])">
in a variable and use this in a loop?

Or there any other solutions ? i use xlst 1.1.

Thank you, Joeri

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.