我有一个如下的 xml 文件 propNode.xml
<NODES>
<NODE>
<NODELINE CLASS="Item" TYPE="Item" >
<ATTR_NODES>
<ATTR_NODE NAME="myName" />
<ATTR_NODE NAME="myDesc />
</ATTR_NODES>
</NODELINE>
<NODELINE CLASS="Item1" TYPE="Item1" >
<ATTR_NODES>
<ATTR_NODE NAME="myName1" />
<ATTR_NODE NAME="myDesc1" />
</ATTR_NODES>
</NODELINE>
<NODELINE CLASS="Item2" TYPE="Item2" >
<ATTR_NODES>
<ATTR_NODE NAME="myName2" />
<ATTR_NODE NAME="myDesc2" />
</ATTR_NODES>
</NODELINE>
</NODE>
</NODES>
我想读取这个xml并使用它,我需要合并以下两个xml文件 source.xml
<NODES>
<NODE>
<NODELINE CLASS="Item" TYPE="Item" >
<ATTR_NODES>
<ATTR_NODE NAME="myName" VALUE="myNameValue" />
<ATTR_NODE NAME="myDesc" VALUE="test-myDescValue" />
<ATTR_NODE NAME="myId" VALUE="test-myIdValue" />
</ATTR_NODES>
</NODELINE>
<NODELINE CLASS="Item1" TYPE="Item1" >
<ATTR_NODES>
<ATTR_NODE NAME="myName1" VALUE="myNameValue1" />
<ATTR_NODE NAME="myDesc1" VALUE="myDescValue1"/>
<ATTR_NODE NAME="myId1" VALUE="myIdValue1" />
</ATTR_NODES>
</NODELINE>
<NODELINE CLASS="Item2" TYPE="Item2" >
<ATTR_NODES>
<ATTR_NODE NAME="myName2" VALUE="test-myNameValue2" />
<ATTR_NODE NAME="myDesc2" VALUE="myDescValue2"/>
<ATTR_NODE NAME="myId2" VALUE="test-myIdValue2" />
</ATTR_NODES>
</NODELINE>
</NODE>
</NODES>
和target.xml
<NODES>
<NODE>
<NODELINE CLASS="Item" TYPE="Item" >
<ATTR_NODES>
<ATTR_NODE NAME="myName" VALUE="myNameValue" />
<ATTR_NODE NAME="myDesc" VALUE="myDescValue" />
<ATTR_NODE NAME="myId" VALUE="myIdValue" />
</ATTR_NODES>
</NODELINE>
<NODELINE CLASS="Item1" TYPE="Item1" >
<ATTR_NODES>
<ATTR_NODE NAME="myName1" VALUE="myNameValue1" />
<ATTR_NODE NAME="myDesc1" VALUE="myDescValue1"/>
<ATTR_NODE NAME="myId1" VALUE="myIdValue1" />
</ATTR_NODES>
</NODELINE>
<NODELINE CLASS="Item2" TYPE="Item2" >
<ATTR_NODES>
<ATTR_NODE NAME="myName2" VALUE="myNameValue2" />
<ATTR_NODE NAME="myDesc2" VALUE="myDescValue2"/>
<ATTR_NODE NAME="myId2" VALUE="myIdValue2" />
</ATTR_NODES>
</NODELINE>
</NODE>
</NODES>
条件是读取propNode.xml,如果@NAME的值在source.xml和target.xml中匹配,那么需要比较source.xml和target.xml中@VALUE的值,并输出一个xml创建如下:
期望输出.xml
<NODES>
<NODE>
<NODELINE CLASS="Item" TYPE="Item" >
<ATTR_NODES>
<ATTR_NODE NAME="myName" SRCVALUE="myNameValue" TGTVALUE="myNameValue" ISDIFF="false" />
<ATTR_NODE NAME="myDesc" SRCVALUE="test-myDescValue" TGTVALUE="myDescValue" ISDIFF="true" />
</ATTR_NODES>
</NODELINE>
<NODELINE CLASS="Item1" TYPE="Item1" >
<ATTR_NODES>
<ATTR_NODE NAME="myName1" SRCVALUE="myNameValue1" TGTVALUE="myNameValue1" ISDIFF="false" />
<ATTR_NODE NAME="myDesc1" SRCVALUE="myDescValue1" TGTVALUE="myDescValue1" ISDIFF="false" />
</ATTR_NODES>
</NODELINE>
<NODELINE CLASS="Item2" TYPE="Item2" >
<ATTR_NODES>
<ATTR_NODE NAME="myName2" SRCVALUE="test-myNameValue2" TGTVALUE="myNameValue2" ISDIFF="true" /> />
<ATTR_NODE NAME="myDesc2" SRCVALUE="myDescValue2" TGTVALUE="myDescValue2" ISDIFF="false" />
</ATTR_NODES>
</NODELINE>
</NODE>
</NODES>
如果在propNode.xml 中选择了@NAME 的值,则desiredOutput.xml 应该包含来自源和目标的@VALUE 的值。如果@VALUE 的值不同,则@ISDIFF 的值应为“true”,否则为“false”。
这整个操作可以使用 xslt 吗?类似于使用 propNode.xml 生成 xsl,然后将其应用于 source.xml 和 target.xml 以生成所需的输出?这个 xsl 会是什么样子?