Re: [xsl] keys and variables VIII

Subject: Re: [xsl] keys and variables VIII
From: Steve <subsume@xxxxxxxxx>
Date: Wed, 2 Aug 2006 14:38:24 -0400
I could shed a tear.

-S

On 8/2/06, G. Ken Holman <gkholman@xxxxxxxxxxxxxxxxxxxx> wrote:
At 2006-08-02 13:41 -0400, Steve wrote:
>Having some difficulty with output. Perhaps someone can shed some
>light as to why.

It appears you were searching the wrong file and key table for the records.

>I am scoring for output that looks like: ==>
>       <tr><td>Cognitive</td><td>50</td></tr>
>       <tr><td>Physical</td><td>50</td></tr>
>       <tr><td>Hearing</td><td>46</td></tr>
>       <tr><td>Mental</td><td>50</td></tr>
>       <tr><td>None</td><td>23</td></tr>

The test data appears to give results of
0,5,0,0,0,1,0 for the above, please confirm that
is what you were expecting with the test data you provided.

>The number above indicates the amount of times a disability with an
>oldID corresponding to the type in the first <td></td> appears in the
>whole of /Record/Record
>
>Here's my code (tested and parsing) ==>

I've added the stylesheet wrapper and I removed the unnecessary key for
oldID.

>Disab.xml ==> > ><disabilities> > <option oldID="204" type="Cognitive" name="Alzheimer's/Dementia"/> >... >Records.xml ==> > ><Records> > <Record> > <disabPrimary>200</disabPrimary> >...

I believe the example below gives you the results
you are looking for.  It appears you were going
into the definitions file and doing the count,
instead of going into the records file and doing
the count.  It has to be the records file since I
understand from your description that file has the elements being counted.

I hope you find the example below helpful.  Thank
you for making it quick to review.

. . . . . . . . . . Ken

T:\ftemp>type Disab.xml
<?xml version="1.0" encoding="US-ASCII"?>
<disabilities>
       <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="301" type="Cognitive" name="Autism"/>
       <option oldID="100" type="Visual" name="Blind"/>
       <option type="Physical" name="Blood disorders" />
       <option oldID="413" type="Physical" name="Cancer"/>
       <option oldID="400" type="Cognitive" name="Cerebral Palsy"/>
       <option oldID="410" type="Physical" name="Chronic Fatigue
Syndrome"/>
       <option oldID="305" type="Cognitive" name="Cognitive-Other"/>
       <option type="Physical" name="Cystic Fibrosis"/>
       <option oldID="101" type="Hearing" name="Deaf"/>
       <option oldID="302" type="Cognitive" name="Developmental/Mental
Retardation"/>
       <option oldID="414" type="Physical" name="Diabetes"/>
       <option oldID="411" type="Physical" name="Epilepsy/Seizure Dis."/>
       <option type="Physical" name="Fibromyalgia"/>
       <option oldID="101" type="Hearing" name="Hard of Hearing"/>
       <option oldID="415" type="Physical" name="Heart Disease" />
       <option type="Physical" name="Hepatitus"/>
       <option oldID="416" type="Physical" name="HIV/AIDS"/>
       <option type="Physical" name="Kidney disorder/renal failure"/>
       <option oldID="300" type="Cognitive" name="Learning Disabilities"/>
       <option oldID="" type="Physical" name="Lung
disease/disorders/conditions" />
       <option oldID="202" type="Mental" name="Mental Health-Other"/>
       <option oldID="200" type="Mental" name="Mental Illness/Emot.Dis"/>
       <option oldID="418" type="Physical" name="Morbid Obesity"/>
       <option oldID="417" type="Physical" name="Multiple Chemical
Sensitive"/>
       <option oldID="420" type="Multiple" name="Multiple Disability"/>
       <option oldID="403" type="Physical" name="Multiple Sclerosis"/>
       <option oldID="402" type="Physical" name="Muscular Dystophy"/>
       <option oldID="412" type="Physical" name="Neurological-Other"/>
       <option oldID="500" type="None" name="None"/>
       <option oldID="406" type="Physical" name="Orthopedic-Other"/>
       <option oldID="419" type="Physical" name="Physical-Other"/>
       <option oldID="410" type="Physical" name="Post-Polio"/>
       <option oldID="404" type="Physical" name="Spinal Cord Disorders" />
       <option oldID="404" type="Physical" name="Spinal Cord Injuries" />
       <option oldID="409" type="Physical" name="Stroke/Cardiovascular"/>
       <option oldID="201" type="Mental" name="Substance Abuse/Addiction"/>
       <option oldID="303" type="Cognitive" name="Traumatic Brain Injury"
/>
       <option oldID="" type="Visual" name="Visually Impaired"/>
</disabilities>

T:\ftemp>type Records.xml
<?xml version="1.0" encoding="US-ASCII"?>
<Records>
   <Record>
     <disabPrimary>200</disabPrimary>
   </Record>
   <Record>
     <disabPrimary>407</disabPrimary>
   </Record>
   <Record>
     <disabPrimary>419</disabPrimary>
   </Record>
   <Record>
     <disabPrimary>101</disabPrimary>
   </Record>
   <Record>
     <disabPrimary>101</disabPrimary>
   </Record>
   <Record>
     <disabPrimary>101</disabPrimary>
   </Record>
   <Record>
     <disabPrimary>101</disabPrimary>
   </Record>
   <Record>
     <disabPrimary>200</disabPrimary>
   </Record>
   <Record>
     <disabPrimary>101</disabPrimary>
   </Record>
</Records>

T:\ftemp>call xslt steve.xsl steve.xsl steve.out

T:\ftemp>type steve.out
<?xml version="1.0" encoding="utf-8"?>
<tr>
    <td>Cognitive</td>
    <td>0</td>
</tr>
<tr>
    <td>Hearing</td>
    <td>5</td>
</tr>
<tr>
    <td>Mental</td>
    <td>0</td>
</tr>
<tr>
    <td>Multiple</td>
    <td>0</td>
</tr>
<tr>
    <td>None</td>
    <td>0</td>
</tr>
<tr>
    <td>Physical</td>
    <td>1</td>
</tr>
<tr>
    <td>Visual</td>
    <td>0</td>
</tr>
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:variable name="Definitions" select="document('Disab.xml')" />
<xsl:variable name="vP2" select="document('Records.xml')" />
<xsl:key name="options" match="option" use="@type" />
<xsl:key name="records" match="Record" use="disabPrimary" />
<xsl:output indent="yes"/>

<xsl:template match="/" >
   <xsl:for-each select="$Definitions/disabilities/

option[generate-id(.)=generate-id(key('options',@type)[1])]">
     <xsl:sort select="@type"/>
     <tr>
       <td>
         <xsl:value-of select="@type"/>
       </td>
       <td>
         <xsl:variable name="current" select="@oldID"/>
         <xsl:for-each select="$vP2">
           <xsl:value-of select="count(key('records',$current))"/>
         </xsl:for-each>
       </td>
     </tr>
   </xsl:for-each>
</xsl:template>

</xsl:stylesheet>


-- UBL/XML/XSLT/XSL-FO training: Verx, Denmark 06-09-25/10-06 World-wide corporate, govt. & user group UBL, XSL, & XML training. G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx 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

Current Thread