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

generalized unique element

Subject: generalized unique element
From: "Laura Jenkins" <xsl_list@xxxxxxxxxxx>
Date: Wed, 11 Sep 2002 11:54:06 +0000
jenkins element
thanks kalyan..

hello
is it possible to output unique nodes in general from an xml file..

I thot of Muenchen way , but i stood back becase it requires to know the name of the element that has to be unique..
i want the xsl to find out all the elements that duplicate and just gimme one instances of each.


example..

i have an xml file which looks like..

<university-records>
	<univ-ids>
		<univ id = "KSU">
			<name>Kansas State University</name>
			<location>Kansas</location>
		</univ>
		<univ id = "FAU">
			<name>Florida Atlantic University</name>
			<location>Florida</location>
		</univ>
		<univ id = "MSU">
			<name> Mississipi State University</name>
			<location> Mississipi </location>
		</univ>
		<univ id = "OSU">
			<name>Ohio State University</name>
			<location> Ohio </location>
		</univ>
	</univ-ids>
	<university-results>
		<university univ-id = "KSU">100%</university>
		<university univ-id = "MSU">90%</university>
		<university univ-id = "FAU">80%</university>
	</university-results>
</university-records>

i need the out put to be in the following way

<university-records>
	<univ-ids id = "">
		<univ></univ>
	</univ-ids>
	<university-results>
		<university univ-id = ""></university>
	</university-results>
</university-records>

any ideas?
Thanks
From: "Kalyan Kumar Mudumbai" <kalyan_tech@xxxxxxxxxxxxxx>
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
CC: "Laura Jenkins" <xsl_list@xxxxxxxxxxx>
Subject: Re:  merging xml files
Date: 11 Sep 2002 11:27:45 -0000

The following XSL would do:
(though I was not able to filter the redundant universities under univ-ids. your output is similar to the one I get using this xsl file)


<?xml version="1.0"?>
<xsl:stylesheet version='1.0'
				xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:output method="xml" indent='yes'/>

<xsl:param name="univ2" select="'./univ2.xml'"/>
<xsl:param name="univ3" select="'./univ3.xml'"/>

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

<xsl:template match="university-records">
	<xsl:copy>
		<xsl:for-each select="@*">
			<xsl:copy><xsl:value-of select="."/></xsl:copy>
		</xsl:for-each>
		<xsl:apply-templates select="*"/>
	</xsl:copy>
</xsl:template>

<xsl:template match="univ-ids">
	<xsl:copy>
		<xsl:for-each select="@*">
			<xsl:copy><xsl:value-of select="."/></xsl:copy>
		</xsl:for-each>
		<xsl:apply-templates select="univ"/>
		<xsl:copy-of select="document($univ2)//univ-ids/univ/@id[.='OSU']"/>
		<xsl:copy-of select="document($univ3)//univ-ids/*"/>
		<xsl:apply-templates select="university-results"/>
	</xsl:copy>
</xsl:template>

<xsl:template match="univ">
	<xsl:copy-of select="."/>
</xsl:template>

<xsl:template match="university-results">
	<xsl:copy>
		<xsl:for-each select="@*">
			<xsl:copy><xsl:value-of select="."/></xsl:copy>
		</xsl:for-each>
	<xsl:apply-templates select="university"/>
	<xsl:copy-of select="document($univ2)//university-results/*"/>
	<xsl:copy-of select="document($univ3)//university-results/*"/>
	</xsl:copy>
</xsl:template>

<xsl:template match="university">
	<xsl:copy-of select="."/>
</xsl:template>

</xsl:stylesheet>

On Wed, 11 Sep 2002 Laura Jenkins wrote :


i have got a fairly conplicated problem ( atleast for me :( )
i have got 3 xml files that contains university result data from 3 different regions.and i have to merge them into one xml with all the data from 3 xmls. The resultant XML should have the same structure as individual XMLs.
for example,
xml1:
<?xml version="1.0"?>
<university-records>
<univ-ids>
<univ id = "KSU">
<name>Kansas State University</name>
<location>Kansas<location>
</univ>
<univ id = "FAU">
<name>Florida Atlantic University</name>
<location>Florida<location>
</univ>
<univ id = "MSU">
<name> Mississipi State University</name>
<location> Mississipi <location>
</univ>
<univ id = "OSU">
<name>Ohio State University</name>
<location> Ohio <location>
</univ>
</univ-ids>
<university-results>
<university univ-id = "KSU">100%</university>
<university univ-id = "MSU">90%</university>
<university univ-id = "FAU">80%</university>
</university-results>
</university-records>


xml2:
<?xml version="1.0"?>
<university-records>
<univ-ids>
	<univ id = "OSU">
		<name> Ohio State University</name>
		<location> Ohio <location>
	</univ>
	<univ id = "WSU">
		<name> Wisconsin state University</name>
		<location> Wisconsin <location>
	</univ>
	<univ id = "RPI">
		<name> Rensellar polytechnic Institute </name>
		<location> New Jersey <location>
	</univ>
	<univ id = "MSU">
		<name> Mississipi State University</name>
		<location> Mississipi  <location>
	</univ>
</univ-ids>
<university-results>
	<university univ-id = "OSU">70%</university>
	<university univ-id = "WSU">100%</university>
	<university univ-id = "RPI">100%</university>
</university-results>
</university-records>
xml3:
<?xml version="1.0"?>
<university-records>
<univ-ids>
	<univ id = "NSU">
		<name> Newyork State University</name>
		<location> Newyork <location>
	</univ>
	<univ id = "BU">
		<name> Belmont University</name>
		<location> Belmont <location>
	</univ>
	<univ id = "WSU">
		<name>Wisconsin state University</name>
		<location> Wisconsin <location>
	</univ>
	<univ id = "BCM">
		<name> Berklee College of Music</name>
		<location> Berklee <location>
	</univ>
</univ-ids>
<university-results>
	<university univ-id = "NU">70%</university>
	<university univ-id = "BU">60%</university>
	<university univ-id = "BCM">100%</university>
</university-results>
</university-records>


i want the resultant xml to be ...


<university-records>
<univ-ids>

	<univ id = "KSU">
		<name>Kansas State University</name>
		<location>Kansas<location>
	</univ>
	<univ id = "FAU">
		<name>Florida Atlantic University</name>
		<location>Florida<location>
	</univ>
	<univ id = "MSU">
		<name> Mississipi State University</name>
		<location> Mississipi <location>
	</univ>
	<univ id = "OSU">
		<name> Ohio State University</name>
		<location> Ohio <location>
	</univ>
	<univ id = "OSU">
		<name> Ohio State University</name>
		<location> Ohio <location>
	</univ>
	<univ id = "WSU">
		<name> Wisconsin state University</name>
		<location> Wisconsin <location>
	</univ>
	<univ id = "RPI">
		<name> Rensellar polytechnic Institute </name>
		<location> New Jersey <location>
	</univ>
	<univ id = "MSU">
		<name> Mississipi State University</name>
		<location> Mississipi  <location>
	</univ>
	<univ id = "NSU">
		<name> Newyork State University</name>
		<location> Newyork <location>
	</univ>
	<univ id = "BU">
		<name> Belmont University</name>
		<location> Belmont <location>
	</univ>
	<univ id = "WSU">
		<name>Wisconsin state University</name>
		<location> Wisconsin <location>
	</univ>
	<univ id = "BCM">
		<name> Berklee College of Music</name>
		<location> Berklee <location>
	</univ>

</univ-ids>
<university-results>
	<university univ-id = "NU">70%</university>
	<university univ-id = "BU">60%</university>
	<university univ-id = "BCM">100%</university>
	<university univ-id = "OSU">70%</university>
	<university univ-id = "WSU">100%</university>
	<university univ-id = "RPI">100%</university>
	<university univ-id = "KSU">100%</university>
	<university univ-id = "MSU">90%</university>
	<university univ-id = "FAU">80%</university>
</university-results>
</university-records>


Things to be noticed here: The <univ-ids> in each of the xml files have some <univ-id> elements which are there in other xmls as well. for example the
<univ id = "MSU">
<name> Mississipi State University</name>
<location> Mississipi <location>
</univ>
which is in the xml2
similarly..
<univ id = "OSU">
<name> Ohio State University</name>
<location> Ohio <location>
</univ>
is there in both the xml files..


But The final XML should not reflect this.

Any Ideas as to how we can acheive this??

Thanks in advance..
laura

_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list




XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list




_________________________________________________________________
MSN Photos is the easiest way to share and print your photos: http://photos.msn.com/support/worldwide.aspx



XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



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.