[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: For-each and keys()

Subject: Re: For-each and keys()
From: Steve <subsume@xxxxxxxxx>
Date: Wed, 2 Aug 2006 10:53:28 -0400
 Re: For-each and keys()
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>

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.