Reorder xml, first the text nodes, then the nodes with childs [closed]

ThePixel

New Member
Possible Duplicate:
Rebuild magento XML with nodes related to each other, closer together with a transform. This is a double post but with the current tags I didn't get a reply to work with. I will update the other post or delete it.I get this back from Magento and the developer can't change it easy to the "after" example. My parser has some problems parsing this so my question is. Can I transform this with a xsl stylesheet to the "after" example where nodea till nodeh are closer to eachother ans so more readable.It will save me a lot of time investigating the parser.Before: <Envelope encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><Body> <salesOrderInfoResponse> <result type="ns1:salesOrderEntity"> <nodec>value</nodec> <noded>value</noded> <shipping_address type="ns1:salesOrderAddressEntity"> <parent_id type="xsd:string">762</parent_id> <address_type type="xsd:string">shipping</address_type> <firstname type="xsd:string">K</firstname> <lastname type="xsd:string">Jansen</lastname> </shipping_address> <billing_address type="ns1:salesOrderAddressEntity"> <parent_id type="xsd:string">762</parent_id> <address_type type="xsd:string">billing</address_type> <firstname type="xsd:string">K</firstname> <lastname type="xsd:string">Jansen</lastname> </billing_address> <items arrayType="ns1:salesOrderItemEntity[4]" type="ns1:salesOrderItemEntityArray"> <item type="ns1:salesOrderItemEntity"> <item_id type="xsd:string">3105</item_id> </item> <item type="ns1:salesOrderItemEntity"> <item_id type="xsd:string">3106</item_id> </item> <item type="ns1:salesOrderItemEntity"> <item_id type="xsd:string">3107</item_id> </item> <item type="ns1:salesOrderItemEntity"> <item_id type="xsd:string">3108</item_id> </item> </items> <payment type="ns1:salesOrderPaymentEntity"> <parent_id type="xsd:string">762</parent_id> <cc_last4 type="xsd:string"></cc_last4> </payment> <nodea>value</nodea> <nodeb>value</nodeb> <nodee>value</nodee> <nodef>value</nodef> <nodeg>value</nodeg> <nodeh>value</nodeh> </result> </salesOrderInfoResponse></Body>After:<Envelope encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><Body> <salesOrderInfoResponse> <result type="ns1:salesOrderEntity"> <nodea>value</nodea> <nodeb>value</nodeb> <nodec>value</nodec> <noded>value</noded> <nodee>value</nodee> <nodef>value</nodef> <nodeg>value</nodeg> <nodeh>value</nodeh> <shipping_address type="ns1:salesOrderAddressEntity"> <parent_id type="xsd:string">762</parent_id> <address_type type="xsd:string">shipping</address_type> <firstname type="xsd:string">K</firstname> <lastname type="xsd:string">Jansen</lastname> </shipping_address> <billing_address type="ns1:salesOrderAddressEntity"> <parent_id type="xsd:string">762</parent_id> <address_type type="xsd:string">billing</address_type> <firstname type="xsd:string">K</firstname> <lastname type="xsd:string">Jansen</lastname> </billing_address> <items arrayType="ns1:salesOrderItemEntity[4]" type="ns1:salesOrderItemEntityArray"> <item type="ns1:salesOrderItemEntity"> <item_id type="xsd:string">3105</item_id> </item> <item type="ns1:salesOrderItemEntity"> <item_id type="xsd:string">3106</item_id> </item> <item type="ns1:salesOrderItemEntity"> <item_id type="xsd:string">3107</item_id> </item> <item type="ns1:salesOrderItemEntity"> <item_id type="xsd:string">3108</item_id> </item> </items> <payment type="ns1:salesOrderPaymentEntity"> <parent_id type="xsd:string">762</parent_id> <cc_last4 type="xsd:string"></cc_last4> </payment> </result> </salesOrderInfoResponse></Body>I have add a xslt suggestion and modified it a little bit and it's seams to be working: <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()" /> </xsl:copy> </xsl:template> <xsl:template match="result"> <xsl:copy> <xsl:apply-templates select="@*" /> <xsl:apply-templates select="*[ starts-with(local-name(),'node') ]" /> <xsl:apply-templates select="*[not(starts-with(local-name(),'node'))]|processing-instruction()|comment()" /> </xsl:copy> </xsl:template> I know have: <salesOrderInfoResponse> <result type="ns1:salesOrderEntity"> <nodec>value</nodec> <noded>value</noded> <nodea>value</nodea> <nodeb>value</nodeb> <nodee>value</nodee> <nodef>value</nodef> <nodeg>value</nodeg> <nodeh>value</nodeh> <shipping_address type="ns1:salesOrderAddressEntity"> <parent_id type="xsd:string">762</parent_id> <address_type type="xsd:string">shipping</address_type> <firstname type="xsd:string">K</firstname> <lastname type="xsd:string">Jansen</lastname> </shipping_address> <billing_address type="ns1:salesOrderAddressEntity"> <parent_id type="xsd:string">762</parent_id> <address_type type="xsd:string">billing</address_type> <firstname type="xsd:string">K</firstname> <lastname type="xsd:string">Jansen</lastname> </billing_address> <items arrayType="ns1:salesOrderItemEntity[4]" type="ns1:salesOrderItemEntityArray"> <item type="ns1:salesOrderItemEntity"> <item_id type="xsd:string">3105</item_id> </item> <item type="ns1:salesOrderItemEntity"> <item_id type="xsd:string">3106</item_id> </item> <item type="ns1:salesOrderItemEntity"> <item_id type="xsd:string">3107</item_id> </item> <item type="ns1:salesOrderItemEntity"> <item_id type="xsd:string">3108</item_id> </item> </items> <payment type="ns1:salesOrderPaymentEntity"> <parent_id type="xsd:string">762</parent_id> <cc_last4 type="xsd:string"/> </payment> </result> </salesOrderInfoResponse> This is almost correct! I don't understand where the extra spacing comes from but Im on the correct track. Testing it further with real data I dont see the text nodes at the top. In above example it was and my guess is it's because of 'node' command. I created this example and used as text nodes, nodea, nodeb, etc. but in real live the are called orderid,name, quantity.Looking at the xml nodes with childs I can see they all have an attribute type with a value that starts with "ns1:..."
 
Back
Top