ANT + XSLT2.0 + Merge xmls
Posted: Tue Nov 06, 2018 2:13 pm
Hi
Apache Ant(TM) version 1.9.7
XSLT 2.0
We have two xmls in two different folders as below. We need to merge all the services into on xml as show in the expected xml.
tmp/atf/test.xml, tmp/fnd/test.xml, tmp/fsm/test.xml
tmp/atf/test.xml,
=================
tmp/fnd/test.xml,
=================
Expected output:
==================
tmp/common/test.xml
=================
ANT SCRIPT:
XSLT:
Control looping through all the three folders automatically. But I want to loop through the folders in XSLT.
Please suggest any clue to merge the xmls as expected.
Thanks in advance,
Samba.
Apache Ant(TM) version 1.9.7
XSLT 2.0
We have two xmls in two different folders as below. We need to merge all the services into on xml as show in the expected xml.
tmp/atf/test.xml, tmp/fnd/test.xml, tmp/fsm/test.xml
tmp/atf/test.xml,
=================
Code: Select all
<serviceReference>
<services>
<chapterSummary>
<text>This chapter describes t</text>
</chapterSummary>
<service anchor="">
<name>ABC</name>
</service>
<service anchor="">
<name>DEF</name>
</service>
</services>
</serviceReference>
=================
Code: Select all
<serviceReference>
<services>
<chapterSummary>
<text>This chapter describes t</text>
</chapterSummary>
<service anchor="">
<name>XYZ</name>
</service>
<service anchor="">
<name>PQR</name>
</service>
</services>
</serviceReference>
==================
tmp/common/test.xml
=================
Code: Select all
<serviceReference>
<services>
<chapterSummary>
<text>This chapter describes t</text>
</chapterSummary>
<service anchor="">
<name>ABC</name>
</service>
<service anchor="">
<name>DEF</name>
</service>
<service anchor="">
<name>XYZ</name>
</service>
<service anchor="">
<name>PQR</name>
</service>
</services>
</serviceReference>
Code: Select all
<xslt basedir="${dita.temp.dir}" destdir="${dita.temp.dir}${file.separator}common" style="${dita.plugin}${file.separator}xsl${file.separator}common_asset_merger.xsl" includes="atf/ fnd/ fsm/"
filenameparameter="filename"
filedirparameter="filedir"
>
</xslt>
Code: Select all
<xsl:template match="/">
<xsl:message> Current file is <xsl:value-of select="$filename"/> in directory <xsl:value-of select="$filedir"/></xsl:message>
<xsl:variable name="inpath" select="string-join(tokenize(document-uri(/), '/')[position() lt last()], '/')"/>
<xsl:message>inpath:<xsl:value-of select="$inpath"/></xsl:message>
<xsl:variable name="files" select="collection($inpath)"/>
<xsl:for-each select="$files">
<xsl:message> Current processing file is <xsl:value-of select="current()"/></xsl:message>
</xsl:for-each>
</xsl:template>
Please suggest any clue to merge the xmls as expected.
Thanks in advance,
Samba.