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

Re: Filtering duplicate tags

Subject: Re: Filtering duplicate tags
From: "Mukul Gandhi" <gandhi.mukul@xxxxxxxxx>
Date: Tue, 27 May 2008 12:27:53 +0530
Re:  Filtering duplicate tags
With XSLT 2.0, you can accomplish this as following:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">

  <xsl:output method="xml" indent="yes" />

  <xsl:template match="root">
    <root>
      <xsl:for-each-group select="data" group-by="@name">
        <xsl:copy-of select="current-group()[1]" />
      </xsl:for-each-group>
    </root>
  </xsl:template>

</xsl:stylesheet>


On 5/27/08, Buddhi D. Mahindarathne <buddhi@xxxxxxxxxxxxxxxxxxx> wrote:
> Hi All,
>
> Following is my sample xml file.
> I want to filter out similar (duplicated) elements and make a new xml
> which has distinct values.
> Matching and filtering need to be done based on Attribute on the first
> tag,
>
> Ex,
> <data name="LBL_Inch"> --> Attribute "LBL_Inch"
>
>
>
> <root>
>        <data name="LBL_Inch">
>                <value>Inch</value>
>                <comment>Inches</comment>
>        </data>
>        <data name="LBL_MM">
>                <value>mm</value>
>                <comment>MM</comment>
>        </data>
>        <data name="LBL_MM">
>                <value>mm</value>
>                <comment>MM</comment>
>        </data>
> </root>
>
>
>
> After transformation I need a xml file like this,
>
> <root>
>        <data name="LBL_Inch">
>                <value>Inch</value>
>                <comment>Inches</comment>
>        </data>
>        <data name="LBL_MM">
>                <value>mm</value>
>                <comment>MM</comment>
>        </data>
> </root>
>
> Please help me on this...
>
> - Thank you all
>
>
>  ____            _     _ _     _
>  | __ ) _   _  __| | __| | |__ (_)
>  |  _ \| | | |/ _` |/ _` | '_ \| |
>  | |_) | |_| | (_| | (_| | | | | |
>  |____/ \__,_|\__,_|\__,_|_| |_|_|


-- 
Regards,
Mukul Gandhi

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.