xsl-list
[Top] [All Lists]

[xsl] Identifying duplicate nodes within a branch

2008-11-13 09:00:00
Hi Everyone,

I've merged two documents on a set of <view> nodes using the Meunchian method.

<view_doc>
        <view name="view1">
                <column file="dev" id="view1.NAME"></column>
                <column file="dev" id="view1.DESCRIPTION"></column>
        </view>
        <view name="view2">
                <column file="doc" id="view2.ID">text</column>
                <column file="doc" id="view2.TIME_STAMP">text</column>
                <column file="doc" id="view2.CUSTOM0">text</column>
                <column file="dev" id="view2.CUSTOM1"></column>
        </view>
        <view name="view3">
                <column file="doc" id="view3.ID">text</column>
                <column file="doc" id="view3.TIME_STAMP">text</column>
                <column file="doc" id="view3.CREATED_ON">text</column>
                <column file="dev" id="view3.ID"></column>
                <column file="dev" id="view3.TIME_STAMP"></column>
                <column file="dev" id="view3.CREATED_ON"></column>
        </view>
</view_doc>


Now I'm trying to identify the <column> nodes where duplicate @id
values exist. Where there are duplicates, I'd like to include the
nodes where the @file value is "doc." But the output should also
include the unique column nodes, all of which have a @file value of
"dev."


Desired output:

<?xml version="1.0" encoding="UTF-8"?>
<view_doc>
        <view name="view1">
                <column file="dev" id="view1.NAME"></column>
                <column file="dev" id="view1.DESCRIPTION"></column>
        </view>
        <view name="view2">
                <column file="doc" id="view2.ID">text</column>
                <column file="doc" id="view2.TIME_STAMP">text</column>
                <column file="doc" id="view2.CUSTOM0">text</column>
                <column file="dev" id="view2.CUSTOM1"></column>
        </view>
        <view name="view3">
                <column file="doc" id="view3.ID">text</column>
                <column file="doc" id="view3.TIME_STAMP">text</column>
                <column file="doc" id="view3.CREATED_ON">text</column>
        </view>
</view_doc>

In the past few days, I've tried every bit of XSL logic I could find
online, including those in the archives of this list. Some have gotten
me closer than others. Here is my current XSL. It isn't the best
example. Unfortunately, I haven't saved every version Ive tried.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:xalan="http://xml.apache.org/xalan";
exclude-result-prefixes="xalan">
        <xsl:output indent="yes"/>
        <xsl:template match="node()|@*">
                <xsl:copy>
                        <xsl:apply-templates select="@*"/>
                        <xsl:apply-templates/>
                </xsl:copy>
        </xsl:template>
        <xsl:template match="view">
                <xsl:copy>
                        <xsl:for-each select="column">
                                <xsl:choose>
                                        <xsl:when 
test="not(preceding-sibling::column[(_at_)id =
current()/@id] or following-sibling::column[(_at_)id = current()/@id])">
                                                <xsl:apply-templates 
select="self::node()[(_at_)file='dev']"/>
                                        </xsl:when>
                                        <xsl:otherwise>
                                                <xsl:apply-templates 
select="self::node()[(_at_)file='doc']"/>
                                        </xsl:otherwise>
                                </xsl:choose>
                        </xsl:for-each>
                </xsl:copy>
        </xsl:template>
</xsl:stylesheet>


I'd appreciate any advice.

Thanks,
Mark

-- 

Mark Peters
Senior Technical Writer
Saba Software

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