Subject: Re: [xsl] Recursive counting From: Steve <subsume@xxxxxxxxx> Date: Wed, 19 Jul 2006 11:40:47 -0400 |
Much appreciated, but I'm still on the 1.0 train. Havin' trouble using DLLs for Saxon.NET without going Visual Studio crazy. =)
> Well after success with my first recursive template I was all > set to make one of my own, but now shamefully am coming to > the list for advice over something that appears quite simple.
First thing is to recognize this as a grouping problem. For each distinct value of @type you need to do something.
In XSLT 2.0:
<xsl:for-each-group select="/*/options/o" group-by="@type"> <xsl:sort select="current-grouping-key()"/> <out type="{current-grouping-key()}" count="{count(/*/person[@pref=current-group()]}"/> </xsl:for-each-group>
> > XML -------> > > <options> > <o type="A">who</o> > <o type="A">what</o> > <o type="A">when</o> > <o type="B">how</o> > <o type="B">nexus</o> > <o type="B">triumph</o> > <o type="C">alligator</o> > <o type="C">spurn</o> > </option> > > <people> > <person pref="who" /> > <person pref="nexus" /> > <person pref="how" /> > <person pref="alligator" /> > <person pref="spurn" /> > <person pref="triumph" /> > .... etc .... > </people> > > > Desired output -------> > > <!-- @count corresponds to number of times the preference > appeared among the list of <people> ---> > > <out type="A" count="1" /> > <out type="B" count="3" /> > <out type="C" count="1" /> > > > Stipulation: ---------> > > <out>'s must be sorted alphabetically, regardless of <option> order.
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Recursive counting, Michael Kay | Thread | RE: [xsl] Recursive counting, Michael Kay |
RE: [xsl] Recursive counting, Michael Kay | Date | RE: [xsl] Recursive counting, Michael Kay |
Month |