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
<data>
<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"/>
</data>
~/t/ftemp $ xslt david.xml david.xsl
<?xml version="1.0" encoding="utf-8"?>
<result>
<level1>Monday</level1>
<level2>morning</level2>
<level3>Alpha One</level3>
<level3>Alpha Two</level3>
<level3>Alpha Three</level3>
<level1>Tuesday</level1>
<level2>morning</level2>
<level3>Alpha One</level3>
<level3>Alpha Two</level3>
<level2>afternoon</level2>
<level3>Bravo One</level3>
<level3>Bravo Two</level3>
<level3>Bravo Three</level3>
<level2>evening</level2>
<level3>Charlie One</level3>
<level3>Charlie Two</level3>
<level3>Charlie Three</level3>
<level2>night</level2>
<level3>Delta One</level3>
<level3>Delta Two</level3>
<level1>Wednesday</level1>
<level2>morning</level2>
<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"
version="1.0">
<xsl:output indent="yes"/>
<xsl:template match="data">
<result>
<xsl:variable name="groups" select="GROUP"/>
<xsl:for-each select="$groups">
<xsl:if test="generate-id(.)=
generate-id($groups[@dow=current()/@dow][1])">
<level1><xsl:value-of select="@dow"/></level1>
<xsl:variable name="days"
select="$groups[@dow=current()/@dow]"/>
<xsl:for-each select="$days">
<xsl:if test="generate-id(.)=
generate-id($days[@period=current()/@period][1])">
<level2><xsl:value-of select="@period"/></level2>
<xsl:for-each select="$days[@period=current()/@period]">
<level3><xsl:value-of select="@description"/></level3>
</xsl:for-each>
</xsl:if>
</xsl:for-each>
</xsl:if>
</xsl:for-each>
</result>
</xsl:template>
</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(_at_)CraneSoftwrights(_dot_)com
Legal business disclaimers: http://www.CraneSoftwrights.com/legal
--~------------------------------------------------------------------
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>
--~--