[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Merge Two Files

Subject: Re: Merge Two Files
From: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Fri, 03 Jul 2009 17:00:36 +0200
Re:  Merge Two Files
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/

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.