I was using enrich mediator in WSO2 ESB to add a child to a parent element in the payload. The new element got added as the last element of the children where I wanted it as the first. I tried action="sibling" but as per the synapse code it also adds the element after the target element [1]. So I decided to make use of XSLT and following is a sample stylesheet along with the input and expected messages.

Input XML
<root>
   <data>
      <B>value 1</B>
      <C>value 1</C>
      <D>value 1</D>
      <A>value 1</A>
   </data>
</root>
Expected XML
<root>
   <data>
      <A>value 1</A>
      <B>value 1</B>
      <C>value 1</C>
      <D>value 1</D>
   </data>
</root>
Stylesheet 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
   <xsl:output indent="yes" />
   <xsl:strip-space elements="*" />
   <xsl:template match="node() | @*">
      <xsl:copy>
         <xsl:apply-templates select="node() | @*" />
      </xsl:copy>
   </xsl:template>
   <xsl:template match="//A" />
   <xsl:template match="//data">
      <xsl:copy>
         <xsl:copy-of select="//A" />
         <xsl:apply-templates />
      </xsl:copy>
   </xsl:template>
</xsl:stylesheet>
0

Add a comment

About Me
About Me
Subscribe
Subscribe
Popular Posts
Popular Posts
  • "The Snare is a poem which evokes positive attitudes within the reader." (1) Which kind of attitudes are evoked? (2) Show them wit...
  • "Island Spell" by Wendy Whatmore vividly describes a beautiful island. The starts her poem saying that she was caught in an island...
  • Try configuring your SLT ADSL connection yourself. Don't WASTE money for SLT . Here are the settings. Type : PPP...
  • To use java tools (javac, java, applet viewer etc.) from anywhere in the dos prompt java should be configured. Suppose that you have already...
  • A late announcement, a little more than 2 years, I moved to Medium. I won't be making any new posts here in this blog. Please refer/foll...
  • SOURCE: http://www.avidtrader.com/wordpress/wp-content/uploads/2013/01/reports.jpg Recently I was involved in developing a registration...
  • Welcome to WSO2 Application Server 6.0.0, the successor of WSO2 Carbon based Application Server. WSO2 Application Server 6.0.0 is a complet...
  • I recently came across this requirement where a  xsd:datetime  in the payload is needed to be converted to a different date time format as ...
  • Dialog GSM offers its latest service,Budget SMS, to both post paid and pre paid customers. With this service you will be able to send D2D SM...
  • Photo Credit : Prima Yogi FAD Singapore 2015 was held on 5th and 6th of December in Singapore and I participated at the event. FAD (F...
Labels
My Links
Blogs I read
Blogs I read
Loading