xsl-list
[Top] [All Lists]

Grouping - Combining Nodes

2005-12-16 08:21:44

Venerable XSLT Sages -

I'm using XSLT 1.0 to pull content from an XML data set to build a class
index. I've solved the first two pieces of the puzzle: Extract the
information from each drug topic and sort the index by class-name. However,
I'm bogged down and the third part: When multiple index entries have the
same class-name, combine them into a single index entry.

For example, in the snippet below, there are four class-items, sorted
alphabetically. The middle two have the same class name:

<class-index>
   <class-item>
      <class-name>Aminoglycoside</class-name>
      <class-reflist>
         <class-ref xref="fandc-atoz0479">Kanamycin Sulfate</class-ref>
      </class-reflist>

   </class-item>
   <class-item>
      <class-name>Analgesic</class-name>
      <class-reflist>
         <class-ref xref="fandc-atoz0483">Ketoprofen</class-ref>
      </class-reflist>
   </class-item>

   <class-item>
      <class-name>Analgesic</class-name>
      <class-reflist>
         <class-ref xref="fandc-atoz0484">Ketorolac Tromethamine</class-ref>
      </class-reflist>
   </class-item>

   <class-item>
      <class-name>Anti-infective</class-name>
      <class-reflist>
         <class-ref xref="fandc-atoz0482">Ketoconazole</class-ref>
      </class-reflist>
   </class-item>
</class-index>

I would like to combine those two into a single class-item that references
all related drug topics (basically move all related class-ref elements into
the same class-item under the class-name):

<class-index>
   <class-item>
      <class-name>Aminoglycoside</class-name>
      <class-reflist>
         <class-ref xref="fandc-atoz0479">Kanamycin Sulfate</class-ref>
      </class-reflist>
   </class-item>

   <class-item>
      <class-name>Analgesic</class-name>
      <class-reflist>
         <class-ref xref="fandc-atoz0483">Ketoprofen</class-ref>
         <class-ref xref="fandc-atoz0484">Ketorolac Tromethamine</class-ref>
     </class-reflist>
   </class-item>

   <class-item>
      <class-name>Anti-infective</class-name>
      <class-reflist>
         <class-ref xref="fandc-atoz0482">Ketoconazole</class-ref>
      </class-reflist>
   </class-item>
</class-index>

Can this be done in XSLT 1.0. If so, how? Any tips will be appreciated.

=======================
Douglas Rudder
XML Analyst
WoltersKluwer Health - Clinical Tools
77 West Port Plaza, Suite 450
Phone:  314-216-2227
e-mail:  drudder(_at_)drugfacts(_dot_)com
www.drugfacts.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>