我正在尝试使用Smooks配置将下面的XML转换为另一个XML,并且Order_header和Order_line的顺序没有按预期显示,我尝试上下移动自由制作者部分并且没有任何效果。
源XML结构
<Order>
<Order_Header>
<OrdNumber>1</OrdNumber>
<CustomerName>ABC</CustomerName>
<Order_Line>
<ItemCode>Item1</ItemCode>
<ItemDesc>Item A</ItemDesc>
<Quantity>2</Quantity>
</Order_Line>
<Order_Line>
<ItemCode>Item2</ItemCode>
<ItemDesc>Item B</ItemDesc>
<Quantity>1</Quantity>
</Order_Line>
</Order_Header>
<Order_Header>
<OrdNumber>2</OrdNumber>
<CustomerName>XYZ</CustomerName>
<Order_Line>
<ItemCode>Item1</ItemCode>
<ItemDesc>Item A</ItemDesc>
<Quantity>2</Quantity>
</Order_Line>
<Order_Line>
<ItemCode>Item2</ItemCode>
<ItemDesc>Item B</ItemDesc>
<Quantity>1</Quantity>
</Order_Line>
<Order_Line>
<ItemCode>Item3</ItemCode>
<ItemDesc>Item C</ItemDesc>
<Quantity>1</Quantity>
</Order_Line>
</Order_Header>
</Order>
预期输出XML
<ORDERS>
<STRUCTTYPE TYPE="1">
<DEFAULTS>
<DIRECT>2</DIRECT>
<DOCTYPE>ORDERS05</DOCTYPE>
</DEFAULTS>
<ONUM>1</ONUM>
<CNAME>ABC</CNAME>
<OLINE>
<ITEM>Item1</ITEM>
<QTY>2</QTY>
</OLINE>
<OLINE>
<ITEM>Item2</ITEM>
<DESC>Item B</DESC>
<QTY>1</QTY>
</OLINE>
<ONUM>2</ONUM>
<CNAME>XYZ</CNAME>
<OLINE>
<ITEM>Item1</ITEM>
<QTY>2</QTY>
</OLINE>
<OLINE>
<ITEM>Item2</ITEM>
<QTY>1</QTY>
</OLINE>
<OLINE>
<ITEM>Item3</ITEM>
<QTY>1</QTY>
</OLINE>
</STRUCTTYPE>
</ORDERS>
我的Smooks配置
<?xml version="1.0" encoding="UTF-8"?>
<smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd"
xmlns:core="http://www.milyn.org/xsd/smooks/smooks-core-1.3.xsd"
xmlns:ftl="http://www.milyn.org/xsd/smooks/freemarker-1.1.xsd">
<core:filterSettings type="SAX" defaultSerialization="false" />
<resource-config selector="orders,order_header,order_line">
<resource>org.milyn.delivery.DomModelCreator</resource>
</resource-config>
<ftl:freemarker applyOnElement="orders">
<ftl:template><!--
<ORDERS>
<STRUCTTYPE TYPE="1">
<DEFAULTS>
<DIRECT>2</DIRECT>
<DOCTYPE>ORDERS05</DOCTYPE>
</DEFAULTS>
<OHEADER>
<?TEMPLATE-SPLIT-PI?>
<OHEADER>
</STRUCTTYPE>
</ORDERS>
--></ftl:template>
</ftl:freemarker>
<ftl:freemarker applyOnElement="order_header">
<ftl:template><!--
<ONUM>${order_header.OrdNumber}</ONUM>
<CNAME>${order_header.CustomerName}</CNAME>
--></ftl:template>
</ftl:freemarker>
<ftl:freemarker applyOnElement="order_line">
<ftl:template>
<!--
<OLINE>
<ITEM>${.vars["order_line"]["ItemCode"]}</ITEM>
<QTY>${.vars["order_line"]["Quantity"]}</QTY>
</OLINE>
--></ftl:template>
</ftl:freemarker>
</smooks-resource-list>
结果我得到的是,即 Order_header 信息<ONUM>1</ONUM><CNAME>ABC</CNAME>
出现在 Order_line {{1}下方}。实际上Order_header应该出现在Order_line之前。请帮忙!
<OLINE><ITEM>Item1</ITEM><QTY>2</QTY></OLINE>