如何代表给定数字创建元素?

时间:2019-05-28 09:33:22

标签: xslt

正常订单有订单行。预购没有订购单,但确实告诉我可以收到多少订单。接收订单的应用程序可以处理带有订单行的订单。因为我们现在还使用预购订单,所以我想创建与预购订单中相同数量的空订单行,以便应用程序可以接受edi。

我已经创建了一张支票,以查看其是否包含订单行或预购订单。

示例传入代码,在这种情况下,“金额3”表示应该有3条订单行:

<WarehouseOutboundOrder>
    <Amount>3</Amount>
    <OrderDate>27-05-2019 13:22</OrderDate>
    <CreationReason>E01_NEW_PREORDER</CreationReason>
</WarehouseOutboundOrder>

预期的外发代码:

<WarehouseOutboundOrder>
    <Amount>3</Amount>
    <OrderDate>27-05-2019 13:22</OrderDate>
    <CreationReason>E01_NEW_PREORDER</CreationReason>
    <WarehouseOutboundOrderLine>
        <Quantity></Quantity>
        <Description></Description>
    </WarehouseOutboundOrderLine>
    <WarehouseOutboundOrderLine>
        <Quantity></Quantity>
        <Description></Description>
    </WarehouseOutboundOrderLine>
    <WarehouseOutboundOrderLine>
        <Quantity></Quantity>
        <Description></Description>
    </WarehouseOutboundOrderLine>
</WarehouseOutboundOrder>

如何使用xslt实现此目的?

1 个答案:

答案 0 :(得分:0)

怎么样:

XSLT 2.0

<xsl:stylesheet version="2.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:template match="WarehouseOutboundOrder">
    <xsl:copy>
        <xsl:copy-of select="*"/>
        <xsl:for-each select="1 to Amount">
            <WarehouseOutboundOrderLine>
                <Quantity/>
                <Description/>
            </WarehouseOutboundOrderLine>        
        </xsl:for-each>
    </xsl:copy>
</xsl:template>

</xsl:stylesheet>

演示https://xsltfiddle.liberty-development.net/gWvjQfM