I need to:
input.xml
(file below) to the format of output.xml
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.