Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


[xsl] Re: For-each and keys()

From: Steve <subsume@--------->
To:
Date: 8/2/2006 2:54:00 PM
Could someone else inspect?



Half of the solutions I've received used two (one nested) key
functions, and half didn't.

Here is the current progress:



http://www.biglist.com/lists/xsl-list/archives/200607/msg00908.html



Thanks,



-Steve



On 7/31/06, Steve <subsume@xxxxxxxxx> wrote:
Hey group,



Trying to come up with key declarations for the below XML trees (which
are both contained within $variables

At the end of the day, I need output that resembles



        <output type="Cognitive"  count="50" />
        <output type="Physical"  count="26" />
        <output type="Visual"  count="34" />
        <output type="Hearing"  count="90" />
        <output type="Mental"  count="11" />
        <output type="None"  count="1" />

The count, in this case, is the amount of times a Record/disabPrimary
corresponds to any disabilities/option/@oldID.  These must then be
grouped by their @type and appear only once in the table.

Sorry to post so much but in trying to score for brevity I have
obviously overcorrected and gone straight to muddled ambiguity in
previous posts. Please let me know if there is anything too vague that
I may elaborate upon.
---

My current XSL has the problem of not using key in a meaningful way
(always returns 0) and also produces a row for each Record, although
it does order them by type.

XSL goes something like:



<xsl:key name="options" match="option" use="@type" />
<xsl:key name="oldID" match="Record" use="disabPrimary" />
<xsl:variable name="$Definitions" select="Document(Disabilities.xml)" />
<xsl:variable name="$Var" select="Document(Records.xml)" />
<xsl:template match="Record" mode="x">
        <xsl:param name="type" />
        <tr>
                <td>
                        <xsl:value-of select="$type" />
                </td>
                <td>
                        <xsl:variable name="current" select="disabPrimary" />
                        <xsl:for-each select="$Definitions/disabilities">
                                <xsl:value-of select="count(key('oldID',$current))" />
                        </xsl:for-each>
                </td>
        </tr>
</xsl:template>
<xsl:template match="/" >
        <html>
                <head>
                        <link rel="stylesheet" href="performance.css" />
                </head>
                <body>
                        <table>
                                <xsl:for-each
select="$Definitions/disabilities/option[generate-id(.)=generate-id(key('options',@type)[1])]">
                                        <xsl:sort select="@type"/>
                                        <xsl:apply-templates mode="x" elect="$Var/Records/Record">
                                                        <xsl:with-param name="type" select="@type" />
                                        </xsl:apply-templates>
                                </xsl:for-each>
                        </table>
                </body>
        </html>
</xsl:template>





XML below



<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>

<Records>
        <Record>
                <disabPrimary>200</disabPrimary>
        </Record>
        <Record>
                <disabPrimary>407</disabPrimary>
        </Record>
        <Record>
                <disabPrimary>101</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>

<!--       *And hundreds more* -->



</Records>


transparent
Print
Mail
Digg
delicious
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent