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

Re: suppressing duplicate data points contained in xml

Subject: Re: suppressing duplicate data points contained in xml data
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Tue, 26 Apr 2011 07:25:21 -0400
Re:  suppressing duplicate data points contained in xml
At 2011-04-26 06:45 -0400, David wrote:
I have a 3 column table that I want to display data coming from and XML
file.  The data contains duplicates in the first two columns.  Is there a
way to print the data in the columns only when it changes? In other words,
suppress when it's duplicated?

Yes, this is a typical grouping exercise ... just grouping at two levels of depth.

Desired XSL output would be something like: Unfortunately I must stick w/
XSL Version 1.0 as I am running on an AIX FOP engine

When not using XSLT 2, I find sometimes the variable-based grouping method is easier to understand than the key-based grouping method.

The principle is to put the items needing grouping into a variable and just finding the first of each value in that variable. At that point, work with the others in that variable of that value to do whatever you need, including making more groups in other variables.

I hope the example below helps. You don't say how you want the output structured, so I just made something simple.

. . . . . . . . . . Ken

~/t/ftemp $ cat david.xml
<GROUP  dow="Monday" period="morning" description="Alpha One"/>
<GROUP  dow="Monday" period="morning" description="Alpha Two"/>
<GROUP  dow="Monday" period="morning" description="Alpha Three"/>
<GROUP  dow="Tuesday" period="morning" description="Alpha One"/>
<GROUP  dow="Tuesday" period="morning" description="Alpha Two"/>
<GROUP  dow="Tuesday" period="afternoon" description="Bravo One"/>
<GROUP  dow="Tuesday" period="afternoon" description="Bravo Two"/>
<GROUP  dow="Tuesday" period="afternoon" description="Bravo Three"/>
<GROUP  dow="Tuesday" period="evening" description="Charlie One"/>
<GROUP  dow="Tuesday" period="evening" description="Charlie Two"/>
<GROUP  dow="Tuesday" period="evening" description="Charlie Three"/>
<GROUP  dow="Tuesday" period="night" description="Delta One"/>
<GROUP  dow="Tuesday" period="night" description="Delta Two"/>
<GROUP  dow="Wednesday" period="morning" description="Alpha One"/>
<GROUP  dow="Wednesday" period="morning" description="Alpha Two"/>
~/t/ftemp $ xslt david.xml david.xsl
<?xml version="1.0" encoding="utf-8"?>
   <level3>Alpha One</level3>
   <level3>Alpha Two</level3>
   <level3>Alpha Three</level3>
   <level3>Alpha One</level3>
   <level3>Alpha Two</level3>
   <level3>Bravo One</level3>
   <level3>Bravo Two</level3>
   <level3>Bravo Three</level3>
   <level3>Charlie One</level3>
   <level3>Charlie Two</level3>
   <level3>Charlie Three</level3>
   <level3>Delta One</level3>
   <level3>Delta Two</level3>
   <level3>Alpha One</level3>
   <level3>Alpha Two</level3>
</result>~/t/ftemp $ cat david.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

<xsl:output indent="yes"/>

<xsl:template match="data">
    <xsl:variable name="groups" select="GROUP"/>
    <xsl:for-each select="$groups">
      <xsl:if test="generate-id(.)=
        <level1><xsl:value-of select="@dow"/></level1>
        <xsl:variable name="days"
        <xsl:for-each select="$days">
          <xsl:if test="generate-id(.)=
            <level2><xsl:value-of select="@period"/></level2>
            <xsl:for-each select="$days[@period=current()/@period]">
              <level3><xsl:value-of select="@description"/></level3>

</xsl:stylesheet>~/t/ftemp $

Contact us for world-wide XML consulting & instructor-led training
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

Current Thread


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.
First Name
Last Name
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.