我需要在我的 biztalk 项目中映射以下输入消息实例,以便程序检查每组客户记录是否存在重复的债务人信息值。如果存在重复值,内联 XSLT 模板会检查重复记录中总和的最大值,并将目标发票信息代码更改为值“Al”。
输入:
<customer>
<record>
<Debtor>
<Debtor_info1>
<name>Jack</name>
</Debtor_info1>
<Debtor_info2>
<y-value>0123-xxx</y-value>
<postnumber>Nevada 666</postnumber>
</Debtor_info2>
</Debtor>
<invoice_info>
<code></code>
<invoice_address></invoice_address>
<total_amount>6000</total_amount>
</invoice_info>
</record>
<record>
<Debtor>
<Debtor_info1>
<name>Jack</name>
</Debtor_info1>
<Debtor_info2>
<y-value>0123-xxx</y-value>
<postnumber>Nevada 666</postnumber>
</Debtor_info2>
</Debtor>
<invoice_info>
<code></code>
<invoice_address></invoice_address>
<total_amount>3000</total_amount>
</invoice_info>
</record>
<record>
<Debtor>
<Debtor_info1>
<name>Evelyn</name>
</Debtor_info1>
<Debtor_info2>
<y-value>0123-xxx</y-value>
<postnumber>Manchester 666</postnumber>
</Debtor_info2>
</Debtor>
<invoice_info>
<code></code>
<invoice_address></invoice_address>
<total_amount>30</total_amount>
</invoice_info>
</record></customer>
输出:
<customer>
<record>
<Debtor>
<Debtor_info1>
<name>Jack</name>
</Debtor_info1>
<Debtor_info2>
<y-value>0123-xxx</y-value>
<postnumber>Nevada 666</postnumber>
</Debtor_info2>
</Debtor>
<invoice_info>
<code>Al</code>
<invoice_address></invoice_address>
<total_amount>6000</total_amount>
</invoice_info>
</record>
<record>
<Debtor>
<Debtor_info1>
<name>Jack</name>
</Debtor_info1>
<Debtor_info2>
<y-value>0123-xxx</y-value>
<postnumber>Nevada 666</postnumber>
</Debtor_info2>
</Debtor>
<invoice_info>
<code></code>
<invoice_address></invoice_address>
<total_amount>3000</total_amount>
</invoice_info>
</record>
<record>
<Debtor>
<Debtor_info1>
<name>Evelyn</name>
</Debtor_info1>
<Debtor_info2>
<y-value>0123-xxx</y-value>
<postnumber>Manchester 666</postnumber>
</Debtor_info2>
</Debtor>
<invoice_info>
<code></code>
<invoice_address></invoice_address>
<total_amount>30</total_amount>
</invoice_info>
</record></customer>
我尝试使用 Muenchian 分组(XSLT 1.0)以及一个连接到目标模式的内联 xslt 模板和一个 xslt 调用模板以及其他方法来实现这一目标,但没有任何运气。内联模板应该使用记录序列来排序并使用债务人信息值输出total_amount的最大值,但到目前为止我还无法实现所需的输出。我非常感谢在这个问题上的帮助。
我想这是你看待它的一种方式:
XSLT 1.0
<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:strip-space elements="*"/>
<xsl:key name="dup" match="invoice_info" use="../Debtor/Debtor_info1" />
<!-- identity transform -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="invoice_info[count(key('dup', ../Debtor/Debtor_info1)) > 1]">
<xsl:variable name="max-amt">
<xsl:for-each select="key('dup', ../Debtor/Debtor_info1)">
<xsl:sort select="total_amount" data-type="number" order="descending"/>
<xsl:if test="position() = 1">
<xsl:value-of select="total_amount"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<!-- output -->
<xsl:copy>
<xsl:choose>
<xsl:when test="total_amount = $max-amt">
<code>A1</code>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="code"/>
</xsl:otherwise>
</xsl:choose>
<xsl:apply-templates select="invoice_address | total_amount"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
请注意,如果出现平局,将标记具有最大值的所有记录。