[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] Copy one element from one xml file to another


Subject: [xsl] Copy one element from one xml file to another
From: Nishi Bhonsle <nishi.bhonsle@xxxxxxxxxx>
Date: Thu, 21 Oct 2004 14:13:30 -0700

Hi:

I have xml1 based on xsd1 and xml2 based on xsd2. I want to copy the value of the attribute "name" of the "transport" element from xml1 to 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 would do the job in the sense, it outputs the correct value --

<?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?

Thanks, Nishi.


Current Thread
Keywords
xsl