Need help to create an XSL file that will transform the input XML file input.xml to the format of output.xml

前端 未结 1 623
隐瞒了意图╮
隐瞒了意图╮ 2020-12-21 20:25

I need to:

  1. Transform the input.xml (file below) to the format of output.xml
  2. Create another XLS that will display per each am
相关标签:
1条回答
  • 2020-12-21 20:38

    You need to link the quantities to their respective orders by matching the order id. The best way to do this is by using a key:

    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:key name="qty" match="quantity" use="id_order"/>  
    
    <xsl:template match="/">
    <output>
        <orders>
            <xsl:for-each select="output/orders/order"> 
                <order>
                    <xsl:copy-of select="id|number|type"/>
                    <xsl:for-each select="key('qty', id)">
                        <xsl:element name="{unit}">
                            <xsl:value-of select="value"/>  
                        </xsl:element>
                    </xsl:for-each>
                </order>    
            </xsl:for-each>
        </orders>
    </output>
    </xsl:template>
    
    </xsl:stylesheet>
    

    Note that we are assuming that each order has no more than one quantity of each unit (i.e no summing is required). Also it seems to me that the target structure is less useful than what you're starting with.

    0 讨论(0)
提交回复
热议问题