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

How to make this XSLT elimination transformation works

Subject: How to make this XSLT elimination transformation works exclusively for different node parents?
From: Jo Na <jkoe888@xxxxxxxxx>
Date: Fri, 8 Jun 2012 13:43:35 +0700
 How to make this XSLT elimination transformation works
Hi,
I have this input:

<myroot>
    <nodeA id="a">
        <section id="i">
            <item1 id="0" method="create">
                <somechild>a</somechild>
            </item1>

            <item1 id="1" method="create">
                <otherchild>a</otherchild>
            </item1>
        </section>

        <section id="i">
            <item1 id="0" method="create"> <!-- second consecutive
create, we remove this -->
                <somechild>a</somechild>
            </item1>
            <item1 id="0" method="create"> <!-- third consecutive
create, BUT children have different value , so we don't remove this
-->
                <somechild>bbb</somechild>
            </item1>
            <item1 id="3" method="create">
                <other>xx</other>
            </item1>

            <item1 id="0" method="change">
                <otherchild>a</otherchild>
            </item1>
            <item1 id="0" method="change"> <!-- second consecutive
create, we remove this -->
                <otherchild>a</otherchild>
            </item1>
        </section>
    </nodeA>
</myroot>

and this is my xslt 2.0:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   <xsl:output indent="yes"/>
   <xsl:strip-space elements="*"/>

   <xsl:template match="node()|@*">
       <xsl:copy>
           <xsl:apply-templates select="node()|@*"/>
       </xsl:copy>
   </xsl:template>

   <xsl:template
match="*[*][deep-equal(.,preceding::*[name()=current()/name()][@id=current()/
@id][1])]"/>
</xsl:stylesheet>

How to make that works for multiple nodeA with different id? Right now
my XSLT only works for 1 nodeA.
The objective is to remove successive duplicate with the same element
name item1 item2 etc, same id and same method.
This is what the multiple nodeA input and the expected output:
<myroot>
    <nodeA id="a">
        <section id="i">
            <item1 id="0" method="create">
                <somechild>a</somechild>
            </item1>

            <item1 id="1" method="create">
                <otherchild>a</otherchild>
            </item1>
        </section>

        <section id="i">
            <item1 id="0" method="create"> <!-- third consecutive
create, BUT children have different value , so we don't remove this
-->
                <somechild>bbb</somechild>
            </item1>
            <item1 id="3" method="create">
                <other>xx</other>
            </item1>

            <item1 id="0" method="change">
                <otherchild>a</otherchild>
            </item1>
        </section>
    </nodeA>

        <nodeA id="b">
        <section id="i">
            <item1 id="0" method="create">
                <somechild>a</somechild>
            </item1>

            <item1 id="1" method="create">
                <otherchild>a</otherchild>
            </item1>
        </section>

        <section id="i">
            <item1 id="0" method="create"> <!-- third consecutive
create, BUT children have different value , so we don't remove this
-->
                <somechild>bbb</somechild>
            </item1>
            <item1 id="3" method="create">
                <other>xx</other>
            </item1>

            <item1 id="0" method="change">
                <otherchild>a</otherchild>
            </item1>
        </section>
    </nodeA>
</myroot>

Expected Output:

<myroot>
    <nodeA id="a">
        <section id="i">
            <item1 id="0" method="create">
                <somechild>a</somechild>
            </item1>

            <item1 id="1" method="create">
                <otherchild>a</otherchild>
            </item1>
        </section>

        <section id="i">
            <item1 id="0" method="create"> <!-- third consecutive
create, BUT children have different value , so we don't remove this
-->
                <somechild>bbb</somechild>
            </item1>
            <item1 id="3" method="create">
                <other>xx</other>
            </item1>

            <item1 id="0" method="change">
                <otherchild>a</otherchild>
            </item1>
        </section>
    </nodeA>

    <nodeA id="b">
        <section id="i">
            <item1 id="0" method="create">
                <somechild>a</somechild>
            </item1>

            <item1 id="1" method="create">
                <otherchild>a</otherchild>
            </item1>
        </section>

        <section id="i">
            <item1 id="0" method="create"> <!-- third consecutive
create, BUT children have different value , so we don't remove this
-->
                <somechild>bbb</somechild>
            </item1>
            <item1 id="3" method="create">
                <other>xx</other>
            </item1>

            <item1 id="0" method="change">
                <otherchild>a</otherchild>
            </item1>
        </section>
    </nodeA>
</myroot>



Thanks very much.

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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