【发布时间】:2017-03-30 20:06:12
【问题描述】:
<xsl:output indent="yes"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="root">
<xsl:copy>
<xsl:for-each-group select="RemittanceInformation" group-by="IndividualRemittance/ExchangeAssignedPolicyID">
<xsl:copy>
<xsl:variable name="pos" select="position()"/>
<xsl:apply-templates select="EntityAssignedNumber, IndividualRemmittance, current-group()/RemittanceDetail">
<xsl:with-param name="pos" select="$pos"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:for-each-group>
</xsl:copy>
</xsl:template>
<xsl:template match="EntityAssignedNumber">
<xsl:param name="pos"/>
<xsl:copy>
<xsl:value-of select="/root/RemittanceInformation[1]/EntityAssignedNumber + $pos - 1"/>
</xsl:copy>
</xsl:template>
我从 S/O 上超级有用的 martin-honnen 获得了这段代码,但它没有做的一件事是,当 RemittanceInformation 类型的节点没有 IndividualRemmittance 时,它根本不会复制它.
我想要的是当有一个 IndividualRemmittance 时,将它们组合在一起以便没有重复项(代码已经这样做了),但是当它遇到没有 IndividualRemmittance 的 RemittanceInformation 时,它应该正常复制它。
我需要改变什么才能做到这一点?
【问题讨论】:
-
您是否尝试过理解代码?您怀疑需要修改哪一部分?你有没有尝试过?你的尝试结果如何?
-
好吧,分组是由“IndividualREmittance/ExchangeAssignedPolicyID”完成的,但我不知道当没有 IndividualRemittance 存在时,我应该如何...“不”组。我不知道如何设置这个条件。
-
好的,所以您不想将它们分组,而是复制它们。这是两件事。换一种说法,您要做的是 1) 将它们排除在分组之外,以及 2) 分别复制它们。
-
好吧,他们已经被排除在外了,因为他们没有 IndividualRemittance 节点,这很好。现在要在保持编号约定的同时单独复制它们,我不知道如何。你呢?
-
我愿意,但我希望你能建立联系。 :) 复制节点的 XSL 元素是
<xsl:copy>。这并不是那么困难。