Re: [xsl] Adding element to xml snippet using xslt

Subject: Re: [xsl] Adding element to xml snippet using xslt
From: Nishi Bhonsle <nishi.bhonsle@xxxxxxxxxx>
Date: Tue, 22 Feb 2005 13:57:41 -0800
Michael Kay wrote:

<xsl:template match="abc:configuration/drillOutDir">
  <xsl:element name="drillOutDir">
     <xsl:value-of select="abc:configuration/drillOutDir"/>
  </xsl:element>
  </xsl:template>


but that will not do anything unless you apply templates to the
drillOutDir element.



I haven't seen the source document, but even if the above template is invoked, it will only do anything useful if there is a structure something like this:

<abc:configuration>
 <drillOutDir>
   <abc:configuration>
     <drillOutDir>

(namespaces and all).

Hi:
Yes, apparently the source document on which this xslt is run does not contain the 'drillOutDir' element.


I have to migrate the nodes from fileA(source doc) and fileB (which is also a xml doc) to an output xml doc. The xslt is run on fileA in such a manner that all nodes from fileA are copied over(preserving their order) and the common nodes that are present in fileA as well as fileB are merged using the xslt and the output of the merge is written to the output file.

In this particular case, 'drillOutDir' is present in fileB only, which needs to be also present in the ouput file too. The 'started' element is present in fileA as well as fileB, but its version in fileB is newer and hence i need to get the started element from fileB in my output file.

FileA contains --
<abc:configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xsi:schemaLocation="http://oracle.com/
xmlns/abcst/configuration configuration.xsd" locale="en" >
<started status="true"></started>
<server></server>
....
</abc:configuration>
-----------------------------


FileB contains --

<abc:configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xsi:schemaLocation="http://oracle.com/ xmlns/abcst/configuration configuration.xsd" locale="en" >
<drillOutDir></drillOutDir>
<started status="true">This application was stopped.</started>
<server></server>
....
</abc:configuration>
------------------------------


Output file should contain --

<abc:configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xsi:schemaLocation="http://oracle.com/
xmlns/abcst/configuration configuration.xsd" locale="en" >
<drillOutDir></drillOutDir>
<started status="true">This application was stopped.</started>
<server></server>


....
</abc:configuration>

So, according to one of my earlier posts from yesterday, only if I include the 'drillOutDir' element node and the 'started' element node inside the template for the 'server' node, they get copied in the output file, but in that case, the 'started' node gets copied over empty without the 'status' attribute.
Even if I include 'drillOutDir' element node and the 'started' element node in the template of the 'abc:configuration' node or have a separate template for each one of them, they do not get copied in the output file.


Please let me know how I could modify xslt to get the output as seen in the output file above.

Thanks.


Michael Kay http://www.saxonica.com/

Current Thread