# Re: Recursive counting

 Subject: Re: Recursive counting From: Steve Date: Wed, 19 Jul 2006 15:40:40 -0400
```Welp, a morning and an afternoon later I'm no closer to applying this
solution. Here's what I've got.```

```What on earth is happening?
----------
<xsl:key name="options" match="option" use="@type"/>
<xsl:key name="oldID" match="option" use="@oldID"/>
<xsl:key name="prefs" match="disabPrimary" use="."/>```

```<xsl:template match="Records" mode="x">
<xsl:for-each select="document('../../Consumer.xml')/defs/disabs/option[generate-id(.)=generate-id(key('options',@type)[1])]">
<xsl:sort select="@type"/>
<tr>
<td>
<xsl:value-of select="@type" />
</td>
<td>
<xsl:value-of select="count(key('oldID',key('options',@type)/@oldID))" />
<xsl:value-of
select="count(key('prefs',\$vP2//Record[disabPrimary=@oldID])))" />
<xsl:value-of select="count(key('prefs',key('options',@type)/@oldID))" />
</td>
</tr>
</xsl:for-each>
--- and later ....```

```<xsl:apply-templates
select="document('../../Consumer.xml')/cilDefinitions/disabilities" />```

```------
XML  (within variable \$vP2 )
<Records>
<Record>
<disabPrimary>101</disabPrimary>
</Record>
<Record>
<disabPrimary>401</disabPrimary>
</Record>
<Record>
<disabPrimary>201</disabPrimary>
</Record>```

and within Consumer.xml .......

```<option oldID="204" type="Cognitive" name="Alzheimer's/Dementia"/>
<option oldID="407" type="Physical" name="Amputation"/>
<option oldID="405" type="Physical" name="Arthritic Conditions"/>
<option oldID="101" type="Cognitive" name="Autism"/>
<option oldID="100" type="Visual" name="Blind"/>
---------```

Desired output

```<out type="Cognitive" count="X" />
<out type="Physical" count="X" />
<out type="Visual" count="X" />```

<!--- X = count of times @oldID=disabPrimary of @type Cognitive -->

```-Steve
----------------------
XSL Related Suicide.```

On 7/18/06, Steve <subsume@xxxxxxxxx> wrote:
```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.```

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.

### PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!