• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Replace an element value in one xml file with value from another xml

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi:

I have xml1 based on xsd1 and xml2 based on xsd2.
The element "transport" exists in both the xml files even though they are based on different .xsd.
I want to replace the value of the attribute "name" of the "transport" element in xml1 with the one from xml2.

Consider xml1:

<?xml version = '1.0' encoding = 'UTF-8'?>

<applet locale="en">
<transport name="jrmp"/>
<transport name="codebase"/>
....
...
...
</applet>
----------------------------------------
Consider xml2:

<disco:configuration xmlns:Disco=......................... xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=............... >
....
....
<plus helpSet="help">
<transport name="jrmp"/>
<transport name="http"/>
</plus>
</disco:configuration>
-----------------------------------------

I noticed the following xsl when applied to xml1 would outputs the correct values for the transport element in xml1 --

<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:Disco="http://www.oracle.com/discoverer/configuration"
xmlns:fo="http://www.w3.org/1999/XSL/Format">

<xsl:output method="xml" encoding="ISO-8859-1" indent="yes" />

<xsl:template match="transport">
<xsl:call-template name="copy"/>
</xsl:template>

<xsl:template name="copy">
<xsl:copy>
<xsl:apply-templates select="@*" mode="copy" />
<xsl:apply-templates/>
<xsl:value-of select="text()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
-------------------------------------------------

How can I thereafter replace the value for the transport element in xml2 with the values I have from the above transform?
OR

Is there another way to achieve this replacement of element values between 2 xml files based on different schema definitions?

Thanks, N.
_______________________________________________________________________
Edit Comment: Disabled smiles in this post.

- m
[ January 14, 2005: Message edited by: Madhav Lakkapragada ]
 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there another way to achieve this replacement of element values between 2 xml files based on different schema definitions?

If the values for the name attribute in both the 'transport' elements are fixed, then you maybe able to get away with it using a style sheet. If not I don't think you can do it using XSL. I would love to hear otherwise.

And from your example these attributes don't seem to have fixed values.

You could solve it using SAX/DOM but not XSL.
Thanks.

- m
 
reply
    Bookmark Topic Watch Topic
  • New Topic