p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

xslt thread: xsl:key & moving down to next levels


Message #1 by "BrianL" <brianleary@h...> on Sat, 21 Jul 2001 05:46:57
Mike,
Thanks for the advice. I will look for an easier solution.

 You've got five nested xsl:for-each statements, which looks completely
> wrong. Most grouping problems only need two. Think about the hierarchic
> structure of the output you want to produce; for each level of the
> hierarchy, work out which input nodes that level corresponds to, and 
write
> an xsl:for-each that selects the appropriate nodes.
> 
> I suspect you're copying code blindly from examples of Muenchian grouping
> without really understanding how it works. It may be better to build up 
from
> simpler examples until you understand what you're doing.
> 
> Mike Kay
> Software AG
> 
> > -----Original Message-----
> > From: BrianL [mailto:brianleary@h...]
> > Sent: 21 July 2001 05:47
> > To: P2P_XSLT
> > Subject: [xslt] xsl:key & moving down to next levels
> >
> >
> > Hi I am working with microsofts parser and I am looking to
> > create a list
> > of arrays from XML.
> > My XML looks like this;
> > <grouplist>
> > <group><name>Hourly</name><planname>Dental</planname><date>071
> > 301</date><fi
> > lename>group1.pdf</filename></group>
> > <group><name>Salaried</name><planname>medical</planname><date>
> > 071201</date>
> > <filename>group1.pdf</filename></group>
> > <group><name>Hourly</name><planname>life</planname><date>07150
> > 1</date><file
> > name>group1.pdf</filename></group>
> > <group><name>Hourly</name><planname>medical</planname><date>07
> > 1201</date><f
> > ilename>group1.pdf</filename></group>
> > <group><name>Hourly</name><planname>401k</planname><date>07120
> > 1</date><file
> > name>group1.pdf</filename></group>
> > <group><name>Hourly</name><planname>IRA</planname><date>071201
> > </date><filen
> > ame>group1.pdf</filename></group>
> > <group><name>Salaried</name><planname>Dental</planname><date>0
> > 71201</date><
> > filename>group1.pdf</filename></group>
> > </grouplist>
> >
> > and the XSLT that I have so far is this.
> >
> > <xsl:stylesheet version="1.0"
> > xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> > xmlns:fo="http://www.w3.org/1999/XSL/Format">
> > 	<xsl:output method="xml" version="1.0"
> > encoding="UTF-8" indent="yes"/>
> >
> > 	<xsl:key name="groupkey" match="group" use="name" />
> >
> >
> > <xsl:template match="grouplist">
> > <xsl:apply-templates select="group[generate-id(.) =generate-id(key
> > ('groupkey', name)[1])]" /><br/>
> >
> >
> >
> > </xsl:template>
> >
> > <xsl:template match="group">
> > groupOption [<xsl:value-of select="position()"/>] 
> > <xsl:for-each select="key('groupkey', name)">
> > "<xsl:value-of select="name" />";<br/><br/>
> > 		  planOption [<xsl:value-of select="position
> > ()"/>] =<xsl:for-each select="key('groupkey', name)">
> >        		"<xsl:value-of
> > select=".//planname"/>",<br/><br/>
> > 			    yearOption
> > [<xsl:value-of
> > select="position()"/>] =<xsl:for-each select="key('groupkey', name)">
> >        				     "<xsl:value-of
> > select="//date"/>",<br/><br/>
> >
> > 	        fileSelection
> > [<xsl:value-of select="position()"/>] =<xsl:for-each select="key
> > ('groupkey', name)">
> >
> > 	 "<xsl:value-of select="//filename"/>",<br/><br/><br/>
> > 			 </xsl:for-each>
> > 		</xsl:for-each>
> >            </xsl:for-each>
> >
> > </xsl:for-each>
> >
> >
> >
> > </xsl:template>
> >
> >
> > </xsl:stylesheet>
> >
> > Notice that when I add another group element with an hourly
> > name element,
> > it causes havoc. I tried looking at
> > http://www.jenitennison.com/ and I
> > found some info, but I am still confused as to how this
> > drilling down is
> > done with keys & variables.
> > Basically I want to keep drilling down and not show any
> > duplicate elements
> > at each level.
> > Does anyone have any suggestions ?
> > Thank you
> >
> > Brian

  Return to Index