我有一个案例如下。我正在合并 2 个 xml 文件。我比较了两个文件中特定类型的节点,并检查它们的某些特定属性是否相同。如果该属性相同,则合并该节点,如果不合并,则复制文件一的节点。请看下面的逻辑
for-each(file1/nodes)
boolean variable var set to false
for-each (file2/nodes)
when(some_condition)
var = true
/for-each
if(var = false)
do-something
/for-each
我的问题是我无法设置和保留这个变量。由于我对 xslt 非常陌生,因此我需要帮助才能使用 xslt 完成此任务。
<xslt:for-each select="$file1_coverage/packages/package">
<xslt:variable name="file1_package_name" select="@name" />
<!-- I want to declare a boolean variable and set it false-->
<xslt:for-each select="$file2_coverage/packages/package">
<xslt:variable name="file2_package_name" select="@name" />
<xslt:choose>
<xslt:when test="$file1_package_name=$file2_package_name">
<!-- Set the boolean variable to true-->
<package>
<xslt:attribute name="branch-rate">
<xslt:value-of select="(($file1_package_branch_rate * $file1_package_branch_total) + ($file2_package_branch_rate * $file2_package_branch_total)) div ($file1_package_branch_total + $file2_package_branch_total)" />
</xslt:attribute>
</package>
</xslt:when>
</xslt:for-each>
<xslt:when test="boolean Variable is false">
<package>
<xslt:copy-of select="$file1_package/@*" />
<xslt:copy-of select="$file1_package/*" />
</package>
</xslt:when>
</xslt:for-each>