Re: [xsl] suppressing duplicate data points contained in xml data

Subject: Re: [xsl] suppressing duplicate data points contained in xml data
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Tue, 26 Apr 2011 07:25:21 -0400
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="";

<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.
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Legal business disclaimers:

Current Thread