xsl-list
[Top] [All Lists]

[xsl] multiple elements to use for grouping

2009-11-13 08:21:59
HI, I have a hard time articulating this one, but I think the examples
will describe it best. I am trying to help someone sort a group of
Excel-generated content chunks, which means that the overall structure
is flat and I have to deal with siblings a lot. The output is supposed
to be a classified listing. I am using Oxygen with Saxon 9 open-source
and XSLT 2.
Input:
<?xml version="1.0" encoding="UTF-8"?>
<root>
   <row>
       <Classification1>Printing</Classification1>
       <Classification2>Packaging</Classification2>
       <Customer>Modern Press</Customer>
       <City>Fairville</City>
       <Tel>1-888-777-6666</Tel>
       <Fax>1-888-777-5555</Fax>
       <Email>name(_at_)gmail(_dot_)com</Email>
       <Image href="images\logo.eps"/>
       <Website> www.modernprinting.com</Website>
   </row>
   <row>
       <Classification1>Packaging</Classification1>
       <Classification2>Printing</Classification2>
       <Classification3>Binding</Classification3>
       <Customer>Complete Printing</Customer>
       <City>Plainville</City>
       <Tel>1-888-777-4444</Tel>
       <Fax>1-888-777-3333</Fax>
       <Email>name(_at_)gmail(_dot_)com</Email>
       <Image href="images\logo.eps"/>
       <Website> www.completeprinting.com</Website>
   </row>
   <row>
       <Classification1>Binding</Classification3>
       <Customer>The Bindery</Customer>
       <City>Overyonder</City>
       <Tel>1-888-777-2222</Tel>
       <Fax>1-888-777-1111</Fax>
       <Email>name(_at_)gmail(_dot_)com</Email>
       <Image href="images\logo.eps"/>
       <Website> www.thebindery.com</Website>
   </row>
</root>

Desired output: Group all the Customers and their sibling city, phone.
fax, etc. under one unique Classification named from the equality of
values of all Classification, Classification2 and Classification3
elements. In other words, the <Customer> named Modern Printing Press
would show up under each of the three different classifications
(Binding, Packaging and Printing) listed under its parent <data> name.
Complete Printing would show up under both Packaging and Printing. The
Bindery would appear only under Binding.
<directory>
   <listing>
       <Classification>Binding</Classification>
       <Customer>The Bindery</Customer>
       <City>Overyonder</City>
       <Box>7654</Box>
       <Tel>1-888-777-2222</Tel>
       <Fax>1-888-777-1111</Fax>
       <Email>name(_at_)gmail(_dot_)com</Email>
       <Image href="images\logo.eps"/>
       <Website> www.thebindery.com</Website>
       <Customer>Complete Printing</Customer>
       <City>Plainville</City>
       <Box>1234</Box>
       <Tel>1-888-777-4444</Tel>
       <Fax>1-888-777-3333</Fax>
       <Email>name(_at_)gmail(_dot_)com</Email>
       <Image href="images\logo.eps"/>
       <Website> www.completeprinting.com</Website>
   </listing>
   <listing>
       <Classification>Packaging</Classification>
       <Customer>Complete Printing</Customer>
       <City>Plainville</City>
       <Box>1234</Box>
       <Tel>1-888-777-4444</Tel>
       <Fax>1-888-777-3333</Fax>
       <Email>name(_at_)gmail(_dot_)com</Email>
       <Image href="images\logo.eps"/>
       <Website> www.completeprinting.com</Website>
       <Customer>Modern Press</Customer>
       <City>Fairville</City>
       <Box>5294</Box>
       <Tel>1-888-777-6666</Tel>
       <Fax>1-888-777-5555</Fax>
       <Email>name(_at_)gmail(_dot_)com</Email>
       <Image href="images\logo.eps"/>
       <Website> www.mycompany.com</Website>
   </listing>
   <listing>
       <Classification>Printing</Classification>
       <Customer>Complete Printing</Customer>
       <City>Plainville</City>
       <Box>1234</Box>
       <Tel>1-888-777-4444</Tel>
       <Fax>1-888-777-3333</Fax>
       <Email>name(_at_)gmail(_dot_)com</Email>
       <Image href="images\logo.eps"/>
       <Website> www.completeprinting.com</Website>
       <Customer>Modern Press</Customer>
       <City>Fairville</City>
       <Box>5294</Box>
       <Tel>1-888-777-6666</Tel>
       <Fax>1-888-777-5555</Fax>
       <Email>name(_at_)gmail(_dot_)com</Email>
       <Image href="images\logo.eps"/>
       <Website> www.mycompany.com</Website>
   </listing>
</directory>


I had great success helping this person with the project when there was
one Classification in each <data> (thanks to xsl-list archives,
especially Ken Holman). Now that my friend says that a <Customer> can
belong with up to three different headings in the directory, the flat
structure has me confused how to approach the sorting and grouping.
So please help me understand. I know that I go up to the grandparent
axis, <root>, so that I can remove duplicates based upon the entire set
of grandchild <Classification>, <Classification2>, <Classification3>
elements. But how do I create the grouping and remove duplicate value
classifications, would I use
       contains(local-name(),'Classification')
or something of that sort? or is this an occasion for a regex?

And then recasting the unique value of the for-each-group to a single
element named <Classification> would use current-grouping-key?

Is this best done with two passes, or can I do it with a single XLS?
Regards, Dorothy

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