Subject: [xsl] generalized unique element From: "Laura Jenkins" <xsl_list@xxxxxxxxxxx> Date: Wed, 11 Sep 2002 11:54:06 +0000 |
hello is it possible to output unique nodes in general from an xml file..
<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>
<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: [xsl] 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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] merging-xmls, Laura Jenkins | Thread | Re: [xsl] generalized unique elemen, David Carlisle |
RE: [xsl] tag minimisation, Andrew Welch | Date | [xsl] doe alternative?, DPawson |
Month |