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

Re: combining common data within groups.

Subject: Re: combining common data within groups.
From: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Tue, 04 Nov 2008 12:48:52 +0100
Re:  combining common data within groups.
Andy.Lewis@xxxxxxxxxxx wrote:
This is a new area for me. Need to eliminate duplicates that occur
within sub-groups.

XML Input example:
<?xml version="1.0"?>
<root>
	<boxes>
		<box_sizes>
			<value>square</value>
		</box_sizes>
		<box_sizes>
			<value>square</value>
		</box_sizes>
	</boxes>
	<boxes>
		<box_sizes>
			<value>round</value>
		</box_sizes>
		<box_sizes>
			<value>square</value>
		</box_sizes>
	</boxes>
	<color1>red</color1>
	<color2>blue</color2>
</root>


Desired output: <?xml version="1.0" encoding="utf-8"?> <root> <color1>red</color1> <boxes> <box_sizes> <value>square</value> </box_sizes> </boxes> <boxes> <box_sizes> <value>round</value> <value>square</value> </box_sizes> </boxes> </root>


As you can see, I want to eliminate duplicate occurances of
<box_sizes/value> within the <boxes> group.

Here is a stylesheet sample:


<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">

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

  <xsl:key name="by-value"
           match="box_sizes"
           use="concat(generate-id(parent::boxes), '_', value)"/>

  <xsl:template match="root">
    <xsl:copy>
      <xsl:apply-templates select="color1"/>
      <xsl:apply-templates select="boxes"/>
    </xsl:copy>
  </xsl:template>

<xsl:template match="boxes">
<xsl:copy>
<box_sizes>
<xsl:apply-templates select="box_sizes[generate-id() = generate-id(key('by-value', concat(generate-id(parent::boxes), '_', value))[1])]/value"/>
</box_sizes>
</xsl:copy>
</xsl:template>


  <xsl:template match="*">
    <xsl:copy>
      <xsl:apply-templates/>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>


--


	Martin Honnen
	http://JavaScript.FAQTs.com/

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.