[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: multiple elements to use for grouping
Hoskins, Dorothy [OCDUS Non J&J] wrote:
^^^^^^^^^^^^^^^^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@xxxxxxxxx</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@xxxxxxxxx</Email> <Image href="images\logo.eps"/> <Website> www.completeprinting.com</Website> </row> <row> <Classification1>Binding</Classification3> This is not well-formed. <Customer>The Bindery</Customer> <City>Overyonder</City> <Tel>1-888-777-2222</Tel> <Fax>1-888-777-1111</Fax> <Email>name@xxxxxxxxx</Email> <Image href="images\logo.eps"/> <Website> www.thebindery.com</Website> </row> </root> Try whether the following does what you want: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="2.0"> <xsl:output indent="yes"/> <xsl:template match="root"> <directory> <xsl:for-each-group select="row" group-by="Classification1, Classification2, Classification3"> <xsl:sort select="current-grouping-key()"/> <listing> <Classification><xsl:value-of select="current-grouping-key()"/></Classification> <xsl:copy-of select="current-group()/(* except (Classification1, Classification2, Classification3))"/> </listing> </xsl:for-each-group> </directory> </xsl:template> </xsl:stylesheet> -- Martin Honnen http://msmvps.com/blogs/martin_honnen/
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|