xsl-list
[Top] [All Lists]

Re: [xsl] Recursive counting

2006-07-19 11:11:46
Grrrrrrrr should have mentioned the <people> tree is actually a
variable, so the simplicity of using a prefs key is out the window....

Thanks so much for your refined-twice solution, Ken.

-Steve

<out {(_at_)type} {count (of things belonging to @type) }>

On 7/18/06, G. Ken Holman <gkholman(_at_)cranesoftwrights(_dot_)com> wrote:
One more edit ... no need for the current()
function ... that was left over from the variable version I posted.

. . . . . . . . Ken

T:\ftemp>type steve.xml
<?xml version="1.0" encoding="US-ASCII"?>
<data>
   <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>
   </options>
   <people>
     <person pref="who" />
     <person pref="nexus" />
     <person pref="how" />
     <person pref="alligator" />
     <person pref="spurn" />
     <person pref="triumph" />
     .... etc ....
   </people>
</data>

T:\ftemp>type steve.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                 version="1.0">

<xsl:output indent="yes"/>

<xsl:key name="options" match="o" use="@type"/>
<xsl:key name="prefs" match="person" use="@pref"/>

<xsl:template match="/data">
   <output>
     <xsl:for-each select="options/o[generate-id(.)=
                                     generate-id(key('options',@type)[1])]">
       <xsl:sort select="@type"/>
       <out type="{(_at_)type}" 
count="{count(key('prefs',key('options',@type)))}"/>
     </xsl:for-each>
   </output>
</xsl:template>

</xsl:stylesheet>
T:\ftemp>xslt steve.xml steve.xsl con
<?xml version="1.0" encoding="utf-8"?>
<output>
    <out type="A" count="1"/>
    <out type="B" count="3"/>
    <out type="C" count="2"/>
</output>
T:\ftemp>

--
Registration open for UBL training:    Montréal, Canada 2006-08-07
Also for XSL-FO/XSLT training:    Minneapolis, MN 2006-07-31/08-04
Also for UBL/XML/XSLT/XSL-FO training: Varo,Denmark 06-09-25/10-06
World-wide corporate, govt. & user group UBL, XSL, & XML training.
G. Ken Holman                 mailto:gkholman(_at_)CraneSoftwrights(_dot_)com
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
Male Cancer Awareness Aug'05  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>