问题
I have 02 XML files, I need to generate a report with the data combination of both the files. either Out put as an HTML file or Single XML with using XSLT
File1
<FitnessCenter>
<Member id="1" level="platinum">
<Name>Kamal</Name>
<Phone type="home">2921234</Phone>
<Phone type="work">2581247-293</Phone>
<FavoriteColor>brown</FavoriteColor>
<MembershipFee>1000</MembershipFee>
</Member>
<Member id="2" level="silver">
<Name>Wasantha</Name>
<Phone type="home">2934321</Phone>
<Phone type="work">2581247-293</Phone>
<FavoriteColor>green</FavoriteColor>
<MembershipFee>500</MembershipFee>
</Member>
</FitnessCenter>
File2
<FitnessCenter>
<Member id="3" level="platinum">
<Name>Aysha</Name>
<Phone type="home">2926745</Phone>
<Phone type="work">2581245-292</Phone>
<FavoriteColor>black</FavoriteColor>
<MembershipFee>1000</MembershipFee>
</Member>
<Member id="4" level="platinum">
<Name>Nishani</Name>
<Phone type="home">2925647</Phone>
<Phone type="work">2581245-292</Phone>
<FavoriteColor>yellow</FavoriteColor>
<MembershipFee>1000</MembershipFee>
</Member>
</FitnessCenter>
I tried to use below XSL method to combine these two files, but it didn't work,
<xsl:template match="/">
<xsl:copy>
<xsl:copy-of select="*/FitnessCenter()"/>
<xsl:copy-of select="document('File2.xml')/*/FitnessCenter()"/>
</xsl:copy>
</xsl:template>
Please comment if anyone having a solution to do this.
回答1:
Look like your same questions is already answered on below post.
In your try , you have not used third file to do the required processing for final out put
Merging two XML files using XSLT
回答2:
find it here... i hope this will help you.. this is java solution.
Merging different nodes of multiple XML files using JAVA
回答3:
How about:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:template match="/FitnessCenter">
<xsl:copy>
<xsl:copy-of select="Member" />
<xsl:copy-of select="document('File2.xml')/FitnessCenter/Member" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
This is assuming you want to merge all 4 members into a single FitnessCenter element, like this:
<?xml version="1.0" encoding="utf-8"?>
<FitnessCenter>
<Member id="1" level="platinum">
<Name>Kamal</Name>
<Phone type="home">2921234</Phone>
<Phone type="work">2581247-293</Phone>
<FavoriteColor>brown</FavoriteColor>
<MembershipFee>1000</MembershipFee>
</Member>
<Member id="2" level="silver">
<Name>Wasantha</Name>
<Phone type="home">2934321</Phone>
<Phone type="work">2581247-293</Phone>
<FavoriteColor>green</FavoriteColor>
<MembershipFee>500</MembershipFee>
</Member>
<Member id="3" level="platinum">
<Name>Aysha</Name>
<Phone type="home">2926745</Phone>
<Phone type="work">2581245-292</Phone>
<FavoriteColor>black</FavoriteColor>
<MembershipFee>1000</MembershipFee>
</Member>
<Member id="4" level="platinum">
<Name>Nishani</Name>
<Phone type="home">2925647</Phone>
<Phone type="work">2581245-292</Phone>
<FavoriteColor>yellow</FavoriteColor>
<MembershipFee>1000</MembershipFee>
</Member>
</FitnessCenter>
来源:https://stackoverflow.com/questions/20739011/how-to-merge-2-xml-files-in-to-one-with-java-script-or-xsl