xsl-list
[Top] [All Lists]

Re: Skeleton Merge

2005-08-23 03:09:14
I think instead of adopting a merging approach, you could hardcode
element creation in the XSLT (shown as below)..

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">
        
<xsl:output method="xml" indent="yes" />
        
<!-- identity template -->
<xsl:template match="node() | @*">
   <xsl:copy>
     <xsl:apply-templates select="node() | @*" />
   </xsl:copy>
</xsl:template>
        
<xsl:template match="branches">
     <email/>
     <website/>
     <branches>
       <xsl:apply-templates />
     </branches>  
</xsl:template>
   
<xsl:template match="branch/name">
     <name><xsl:apply-templates /></name>
     <address/>
</xsl:template>
   
</xsl:stylesheet>

Regards,
Mukul

On 8/23/05, Saran Toochinda <sarantoo(_at_)gmail(_dot_)com> wrote:
I'm using XForms to collect XML data (company data, 1 file per
company). A skeleton of blank XML file which is based on a schema is
use to present the data input forms. Our schema is change from time to
time with additional data structure as well as corresponding XForms
control. There is no problem with the new file because it always based
on a new skeleton file. The problem arise on the existing files
because XForms bound it's control to existance of data element in
existing document. The newly added XForms controls don't get display
because there is no such data exist before.

My question is how can I merge newly added, blank element to an
existing file using XSLT to reflect the new data structure. For
example: merging existing.xml with skeleton.xml and looking for
somethink like the output below:

File existing.xml:

<company id="123">
  <name>ABC</name>
  <address>NJ</address>
  <phone>123456</phone>
  <fax>56789</fax>
  <branches>
       <branch>
           <name>Branch A</name>
       </branch>
       <branch>
           <name>Branch B</name>
       </branch>
  </branch>
</company>

File skeleton.xml with newly added element:

<company id="">
  <name/>
  <address/>
  <phone/>
  <fax/>
  <email/>              <!-- added -->
  <website/>           <!-- added -->
  <branches>
       <branch>
           <name/>
           <address/>    <!-- added -->
       </branch>
  </branch>
</company>

This is a needed output:

<company id="123">
  <name>ABC</name>
  <address>NJ</address>
  <phone>123456</phone>
  <fax>56789</fax>
  <email/>                           <!-- added -->
  <fax/>                               <!-- added -->
  <branches>
       <branch>
           <name>Branch A</name>
           <address/>               <!-- added -->
       </branch>
       <branch>
           <name>Branch B</name>
           <address/>               <!-- added -->
       </branch>
  </branch>
</company>


The actual schema is very complex and there are many schemas so
looking for a universal transform solution rather than hard coded per
element/file.

Many thanks in advance!

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>
  • Skeleton Merge, Saran Toochinda
    • Re: Skeleton Merge, Mukul Gandhi <=