Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] Merge Two Files

From: Martin Honnen <Martin.Honnen@---.-->
To: xsl-list@-----.------------.---
Date: 7/3/2009 3:01:00 PM
Brad Felix wrote:

> File 1 provides the "master" and the result of the merge should look like:
> 
> <?xml version="1.0"?>
> <chapter>
> <title>Business Ethics and Social Responsibility</title>
> <section id="sec1">
> <title>My Title</title>
> <para id="1">Some content</para>
> <para role="note" id="1">Here is a sample 1 annotation</para>
> <para id="2">Some content</para>
> <para role="note" id="2">Here is a sample 2 annotation</para>
> <para id="3">Some content</para>
> <para role="note" id="3">Here is a sample 3 annotation</para>
> <para id="4">Some content</para>
> <para role="note" id="4">Here is a sample 4 annotation</para>
> <para id="5">Some content</para>
> <para id="6">Some content</para>
> <para id="7">Some content</para>
> <para id="8">Some content</para>
> </section>
> </chapter>

The following does that:

<xsl:stylesheet
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   version="1.0">

   <xsl:output method="xml" indent="yes"/>
   <xsl:strip-space elements="*"/>

   <xsl:template match="@* | node()">
     <xsl:copy>
       <xsl:apply-templates select="@* | node()"/>
     </xsl:copy>
   </xsl:template>

   <xsl:template match="chapter/title">
     <xsl:copy>
       <xsl:text>Business Ethics and Social Responsibility</xsl:text>
     </xsl:copy>
   </xsl:template>

   <xsl:template match="para">
     <xsl:copy>
       <xsl:apply-templates select="@* | node()"/>
     </xsl:copy>
     <xsl:apply-templates 
select="document('file2.xml')/personalnotes/note[@id = current()/@id]"/>
   </xsl:template>

   <xsl:template match="note">
     <para role="note">
       <xsl:apply-templates select="@* | node()"/>
     </para>
   </xsl:template>

</xsl:stylesheet>


-- 

	Martin Honnen
	http://msmvps.com/blogs/martin_honnen/

--~------------------------------------------------------------------
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@l...>
--~--



transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent