Answer found from OTN forum:
Use the below xquery:-
xquery version "1.0" encoding "Cp1252";
(:: pragma parameter="$anyType1" type="xs:anyType" ::)
(:: pragma type="xs:anyType" ::)
declare namespace xf = "http://tempuri.org/OSB%20Project%201/XQ/Test2/";
declare function xf:Test2($anyType1 as element(*))
as element(*) {
let $input:= <STRUCTURE>
<OBJECT_1>
<item>
<MONTH>2013_M06</MONTH>
<INFO_11>ABC</INFO_11>
<INFO_12>2012-04-24</INFO_12>
</item>
<item>
<MONTH>2013_M05</MONTH>
<INFO_11>DEF</INFO_11>
<INFO_12>2012-04-24</INFO_12>
</item>
</OBJECT_1>
<OBJECT_2>
<item>
<MONTH>2013_M06</MONTH>
<INFO_21>11111</INFO_21>
<INFO_22>1</INFO_22>
</item>
<item>
<MONTH>2013_M06</MONTH>
<INFO_21>11111</INFO_21>
<INFO_22>2</INFO_22>
</item>
<item>
<MONTH>2013_M05</MONTH>
<INFO_21>22222</INFO_21>
<INFO_22>1</INFO_22>
</item>
</OBJECT_2>
</STRUCTURE>
let $month := fn:distinct-values($input/OBJECT_1//MONTH/text())
let $out:=<targetStructure>{
for $x in 1 to fn:count($month)
return
<object1>
<month>{$month[$x]}</month>
<info_11>{$input/OBJECT_1/item[./MONTH=$month[$x]]/INFO_11/text()}</info_11>
<info_12>{$input/OBJECT_1/item[./MONTH=$month[$x]]/INFO_12/text()}</info_12>
{for $y in $input/OBJECT_2/item
where $y/MONTH/text()=$month[$x]
return
<object2>
<info_21>{$y/INFO_21/text()}</info_21>
<info_22>{$y/INFO_22/text()}</info_22>
</object2>}
</object1>
}
</targetStructure>
return $out
};
declare variable $anyType1 as element(*) external;
xf:Test2($anyType1)