merging documents
Questions about XML that are not covered by the other forums should go here.
merging documents
Post by aya »
Hi,
I'm new with oxygen and would need a function with which you can merge two documents.
I have two xml docs: in one doc are just a few entries and an other underlaying document contains something like template entries. These two documents should result in a third one which contains the "template" -entries and the modified ones of the first document.
hope you understand what I mean and would be thankful for any hint
kr
aya
I'm new with oxygen and would need a function with which you can merge two documents.
I have two xml docs: in one doc are just a few entries and an other underlaying document contains something like template entries. These two documents should result in a third one which contains the "template" -entries and the modified ones of the first document.
hope you understand what I mean and would be thankful for any hint
kr
aya
Hi Aya,
You can use XSLT for merging two documents. See below a complete example.
Let's consider the master document master.xml:
and the small update document update.xml:
The expected output will be:
All templates from the master document that do not appear in the update document and all the templates in the update document will be in the result.
The following stylesheet will create the output:
Best Regards,
George
You can use XSLT for merging two documents. See below a complete example.
Let's consider the master document master.xml:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<entries>
<template name="t0">value0</template>
<template name="t1">value1</template>
<template name="t2">value2</template>
<template name="t3">value3</template>
<template name="t4">value4</template>
<template name="t5">value5</template>
<template name="t6">value6</template>
<template name="t7">value7</template>
<template name="t8">value8</template>
<template name="t9">value9</template>
</entries>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<entries>
<template name="t3">value3modified</template>
<template name="t7">value7modified</template>
<template name="t10">value10</template>
</entries>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<entries>
<template name="t0">value0</template>
<template name="t1">value1</template>
<template name="t2">value2</template>
<template name="t4">value4</template>
<template name="t5">value5</template>
<template name="t6">value6</template>
<template name="t8">value8</template>
<template name="t9">value9</template>
<template name="t3">value3modified</template>
<template name="t7">value7modified</template>
<template name="t10">value10</template>
</entries>
The following stylesheet will create the output:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<!-- The update document location -->
<xsl:param name="updateDoc" select="'update.xml'"/>
<!-- Copy only the templates that are not found in the update document -->
<xsl:template match="template">
<xsl:if test="not(document($updateDoc)/entries/template[@name=current()/@name])">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:if>
</xsl:template>
<!-- Process the master document and then the update document -->
<xsl:template match="entries">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
<xsl:apply-templates select="document($updateDoc)/entries/node()" mode="update"/>
</xsl:copy>
</xsl:template>
<!-- Copy template for the master document -->
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<!-- Copy template for the update document -->
<xsl:template match="@* | node()" mode="update">
<xsl:copy>
<xsl:apply-templates select="@* | node()" mode="update"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
George
-
- Posts: 4
- Joined: Tue Jun 08, 2004 5:17 pm
mergimg tool
Post by joeandersen »
Hello,
Please try a visual tool ExamXML at [http://www.a7soft.com]
This tool can compare and merge XML documents.
Joe.
Please try a visual tool ExamXML at [http://www.a7soft.com]
This tool can compare and merge XML documents.
Joe.
Return to “General XML Questions”
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service