将两个记录映射到同一个节点,其中一个是另一个子记录的迭代

Mapping two records to same node, where one is an iteration of a child record of the other

我希望创建一个节点到源架构上的节点的迭代。这很容易,但是当我想基于第一个节点的子节点在同一个节点上创建不同的迭代时,麻烦就来了。

<cases>
    <customer>
        <account>
        <name>John Smith</name>
        <address>hello road 321</address>
        <current_balance>100</current_balance>
        <current_balance_date>20180712</current_balance_date>
        </account>
        <invoices>
             <invoice>
                <amount>231</amount>
                <paydate>20183104</paydate>
             </invoice>
             <invoice>
                <amount>2332</amount>
                <paydate>20181204</paydate>
             </invoice>
         </invoices>
     </customer>    
</cases>

每个客户可以有一个 current_balance,但是有几张发票,我需要将它们映射到目标架构上的同一节点,并查看像这样:

<basis>
    <toPay>100</toPay>
    <dateToPay>20180712</dateToPay>
</basis>
<basis>
    <toPay>231</toPay>
    <dateToPay>20183104</dateToPay>
</basis>
<basis>
    <toPay>2332</toPay>
    <dateToPay>20181204</dateToPay>
</basis>

我已经尝试了 table 循环、常规循环、条件循环和创建 xslt(我对它也很缺乏经验),但似乎无法使其工作。我只能做一个或两个。

编辑:我目前正在尝试 xslt-inline-call:

<xsl:template name="basis">

<!-- balance-parameters -->
<xsl:param name="current_balance" />
<xsl:param name="current_balance_date" />

<!-- invoice-parameters -->
<xsl:param name="amount" />
<xsl:param name="paydate" />

<xsl:element name="basis">
    <xsl:element name="toPay"><xsl:value-of select="$current_balance" /></xsl:element>
    <xsl:element name="dateToPay"><xsl:value-of select="$current_balance_date" /></xsl:element>
</xsl:element>

<xsl:for-each select="cases/customer/account/invoices/invoice">
    <xsl:element name="basis">
        <xsl:element name="toPay"><xsl:value-of select="$amount" /></xsl:element>
        <xsl:element name="dateToPay"><xsl:value-of select="$paydate" /></xsl:element>
    </xsl:element>
</xsl:for-each>

</xsl:template>

for-each 根本不输出任何东西,case/customer/invoices/invoice 和case/customer/invoices 我都试过了。我根本无法完成这项工作

首先,确保源Schema有基础并设置为maxOccurs = unbounded。

这个其实很简单。 current_balance 应该只使用链接。

您将需要链接发票和基础的循环 Functoid 以及链接 current_balance 和基础的另一个循环 Functoid。

这应该在 xsl 中创建两个 for-each,您可以使用 Validate Map 查看它们。

这个应该可以。你应该循环 /cases/customer/account/invoices/invoice 而不是 case/customer/invoices/invoice

<xsl:template name="basis"> 
<basis>
    <toPay>
        <xsl:value-of select="/cases/customer/account/current_balance" />
    </toPay>
    <dateToPay>
        <xsl:value-of select="/cases/customer/account/current_balance_date" />
    </dateToPay>
</basis>

<xsl:for-each select="/cases/customer/account/invoices/invoice">
    <basis>
        <toPay>
            <xsl:value-of select="amount" />
        </toPay>
        <dateToPay>
            <xsl:value-of select="paydate" />
        </dateToPay>
    </basis>
</xsl:for-each></xsl:template>