Hi All,
I have an requirenment to merge two xml files based on the values....
Both the xml, which contains table structure like below....
main file(File1.xml)...
<?xml version="1.0" encoding="utf-8"?>
<dita>
<topic>
<title>Terms</title>
<body/>
<reference>
<title>Localizable</title>
<refbody class="- topic/body reference/refbody ">
<table>
<tgroup cols="2" colsep="0" rowsep="1" outputclass="2col.small.table" class="- topic/tgroup ">
<colspec colnum="1" colname="1" colwidth="1.167in" colsep="0" class="- topic/colspec "/>
<colspec colnum="2" colname="2" colwidth="2.041in" colsep="0" class="- topic/colspec "/>
<thead class="- topic/thead ">
<row rowsep="1" class="- topic/row ">
<entry colname="1" colsep="1" class="- topic/entry ">
<p translate="no" class="- topic/p ">Key (or Paragraph tag)</p>
</entry>
<entry colname="2" colsep="1" class="- topic/entry ">
<p translate="no" class="- topic/p ">Value</p>
</entry>
<entry colname="3" class="- topic/entry ">
<p translate="no" class="- topic/p ">Comment</p>
</entry>
</row>
</thead>
<tbody class="- topic/tbody ">
<row rowsep="1" class="- topic/row ">
<entry colname="1" colsep="1" class="- topic/entry ">
<p translate="no" class="- topic/p ">Test1</p>
</entry>
<entry colname="2" colsep="1" class="- topic/entry ">
<p class="- topic/p ">Test1</p>
</entry>
<entry colname="3" class="- topic/entry ">
<draft-comment class="- topic/draft-comment ">
<p class="- topic/p ">Test1 text</p>
</draft-comment>
</entry>
</row>
<row rowsep="1" class="- topic/row ">
<entry colname="1" colsep="1" class="- topic/entry ">
<p translate="no" class="- topic/p ">Test2</p>
</entry>
<entry colname="2" colsep="1" class="- topic/entry ">
<p class="- topic/p ">Test2</p>
</entry>
<entry colname="3" class="- topic/entry ">
<draft-comment class="- topic/draft-comment ">
<p class="- topic/p ">Test2</p>
</draft-comment>
</entry>
</row>
<row rowsep="1" class="- topic/row ">
<entry colname="1" colsep="1" class="- topic/entry ">
<p translate="no" class="- topic/p ">Test</p>
</entry>
<entry colname="2" colsep="1" class="- topic/entry ">
<p class="- topic/p ">Test</p>
</entry>
<entry colname="3" class="- topic/entry ">
<draft-comment class="- topic/draft-comment ">
<p class="- topic/p ">Test</p>
</draft-comment>
</entry>
</row>
</tbody>
</tgroup>
</adobetable>
</refbody>
</reference>
</topic>
</dita>
file2.xml....
<?xml version="1.0" encoding="utf-8"?>
<dita>
<topic DTDVersion="V1.1.3" domains="(topic hi-d) (topic
pr-d) (topic sw-d) (topic adobe-d)" class="- topic/topic " id="WS58b67d046ae8e03c15f1d0a110e67a7921-8000">
<title class="- topic/title ">Localizable Terms</title>
<body class="- topic/body "/>
<reference DTDVersion="V1.1.3" domains="(topic hi-d) (topic
pr-d) (topic sw-d) (topic adobe-d)" class="- topic/topic reference/reference " id="WS58b67d046ae8e03c15f1d0a110e67a7921-7fff">
<title class="- topic/title ">Localizable Terms</title>
<refbody class="- topic/body reference/refbody ">
<adobetable frame="all" colsep="0" rowsep="1" class="+ topic/table adobe-d/adobetable ">
<tgroup cols="2" colsep="0" rowsep="1" outputclass="2col.small.table" class="- topic/tgroup ">
<colspec colnum="1" colname="1" colwidth="1.167in" colsep="0" class="- topic/colspec "/>
<colspec colnum="2" colname="2" colwidth="2.041in" colsep="0" class="- topic/colspec "/>
<thead class="- topic/thead ">
<row rowsep="1" class="- topic/row ">
<entry colname="1" colsep="1" class="- topic/entry ">
<p translate="no" class="- topic/p ">Key (or Paragraph tag)</p>
</entry>
<entry colname="2" colsep="1" class="- topic/entry ">
<p translate="no" class="- topic/p ">Value</p>
</entry>
<entry colname="3" class="- topic/entry ">
<p translate="no" class="- topic/p ">Comment</p>
</entry>
</row>
</thead>
<tbody class="- topic/tbody ">
<row rowsep="1" class="- topic/row ">
<entry colname="1" colsep="1" class="- topic/entry ">
<p translate="no" class="- topic/p ">testing</p>
</entry>
<entry colname="2" colsep="1" class="- topic/entry ">
<p class="- topic/p ">testing</p>
</entry>
<entry colname="3" class="- topic/entry ">
<draft-comment class="- topic/draft-comment ">
<p class="- topic/p ">testing</p>
</draft-comment>
</entry>
</row>
<row rowsep="1" class="- topic/row ">
<entry colname="1" colsep="1" class="- topic/entry ">
<p translate="no" class="- topic/p ">read</p>
</entry>
<entry colname="2" colsep="1" class="- topic/entry ">
<p class="- topic/p ">read</p>
</entry>
<entry colname="3" class="- topic/entry ">
<draft-comment class="- topic/draft-comment ">
<p class="- topic/p ">Test: Text for read</p>
</draft-comment>
</entry>
</row>
<row rowsep="1" class="- topic/row ">
<entry colname="1" colsep="1" class="- topic/entry ">
<p translate="no" class="- topic/p ">only</p>
</entry>
<entry colname="2" colsep="1" class="- topic/entry ">
<p class="- topic/p ">only</p>
</entry>
<entry colname="3" class="- topic/entry ">
<draft-comment class="- topic/draft-comment ">
<p class="- topic/p ">Test: Text for only</p>
</draft-comment>
</entry>
</row>
<row rowsep="1" class="- topic/row ">
<entry colname="1" colsep="1" class="- topic/entry ">
<p translate="no" class="- topic/p ">Test1</p>
</entry>
<entry colname="2" colsep="1" class="- topic/entry ">
<p class="- topic/p ">Test1</p>
</entry>
<entry colname="3" class="- topic/entry ">
<draft-comment class="- topic/draft-comment ">
<p class="- topic/p ">Test1</p>
</draft-comment>
</entry>
</row>
</tbody>
</tgroup>
</adobetable>
</refbody>
</reference>
</topic>
</dita>
With the below xslt attached code snippet, can able to override from file2 to file1 the row which gets matched, but failing to append row when it's not matched.
xslt...
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:variable name="overrides" select="'../../bin/term_overrides.xml'"/>
<xsl:variable name="term2b" select="document($overrides)//tbody/row/entry[1]/p/text()"/>
<xsl:variable name="term.override" select="document($overrides)//tbody/row"/>
<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="tbody">
<tbody>
<xsl:for-each select="row">
<xsl:variable name="r1" select="entry[1]/p"/>
<xsl:choose>
<xsl:when test="$r1[.=$term2b]">
<xsl:copy-of select="$term.override[entry[1]/p[.=$r1]]"/>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</tbody>
</xsl:template>
<xsl:template match="/*">
<xsl:copy>
<xsl:apply-templates/>
<xsl:apply-templates select="//tbody/row[entry[1]/p[.!=$term.override[entry[1]/p/text()]]]"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Please suggest what's get wrong in xslt?
Thanks a lot!!!
Shailesh