我想比较两个xmls然后合并它们.例如:
@H_403_20@myFile1.xml
<?xml version="1.0" encoding="ISO-8859-1"?> <catalog> <data> <title>Title1</title> <description>Description1</description> <myid>1</myid> </data> <data> <title>Title2</title> <description>Description2</description> <myid>2</myid> </data> </catalog>
myFile2.xml
<?xml version="1.0" encoding="ISO-8859-1"?> <catalog> <data> <title>Title1</title> <description>Description1</description> <author>Author1</author> <date>12/34/5678</date> <myid>1</myid> </data> <data> <author>Author2</author> <date>87/65/4321</date> <myid>2</myid> </data> </catalog>
期望的输出:
<?xml version="1.0" encoding="ISO-8859-1"?> <catalog> <data> <title>Title1</title> <description>Description1</description> <myid>1</myid> <author>Author1</author> <date>12/34/5678</date> </data> <data> <title>Title2</title> <description>Description2</description> <myid>2</myid> <author>Author2</author> <date>87/65/4321</date> </data> </catalog>
<?xml version="1.0" encoding="ISO-8859-1"?> <xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" version="1.0" encoding="ISO-8859-1" indent="yes"/> <xsl:variable name="compare" select="'myFile1.xml'"/> <xsl:variable name="with" select="'myFile2.xml'"/> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="*"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> <xsl:variable name="info1" select="document($compare)/catalog/data[myid=current()/myid]/."/> <xsl:variable name="info2" select="document($with)/catalog/data[myid=current()/myid]/."/> <xsl:for-each select="$info1/*"> <xsl:variable name="check1" select="name(current())"/> <!--xsl:text>Current node1 : </xsl:text><xsl:value-of select="$check1"/--> <xsl:for-each select="$info2/*"> <xsl:variable name="check2" select="name(current())"/> <!--xsl:text>Current node2 : </xsl:text><xsl:value-of select="$check2"/--> <xsl:if test="$check1!=$check2"> <xsl:copy-of select="."/> </xsl:if> </xsl:for-each> </xsl:for-each> </xsl:copy> </xsl:template> </xsl:transform>
请帮忙!