0
votes

Thanks for the quick response. I tried both the answers. It is not working as I expected. Please find the below Input and the expected Output. Thanks in Advance

Input: <Billing> <billSummary> <billTo> <accountNumber>130212192</accountNumber> <MSISDN>1234567890</MSISDN> </billTo> <tax> <amount>100.12</amount> <description>TAXES</description> </tax> <charge> <typeCode>ONE_TIME</typeCode> <amount>100.12</amount> <description>ONE_TIME_CHARGE</description> </charge> <charge> <typeCode>ACCESS</typeCode> <amount>100.12</amount> <description>ACCESS_CHARGE</description> </charge> <tax> <amount>100.12</amount> <description>TAXES</description> </tax> <charge> <typeCode>FEATURE</typeCode> <amount>100.12</amount> <description>FEATURE_CHARGE</description> </charge> <deduction> <amount>100.12</amount> <description>ADJUSTMENTS</description> </deduction> <charge> <typeCode>AIRTIME</typeCode> <amount>100.12</amount> <description>AIRTIME_CHARGE</description> </charge> <charge> <typeCode>LONG_DISTANCE</typeCode> <amount>100.12</amount> <description>LONG_DISTANCE_CHARGE</description> </charge> <charge> <typeCode>ROAMING</typeCode> <amount>100.12</amount> <description>ROAMING_CHARGE</description> </charge> <deduction> <amount>100.12</amount> <description>ADJUSTMENTS</description> </deduction> </billSummary> <billSummary> <billTo> <accountNumber>130212192</accountNumber> <MSISDN>1234567890</MSISDN> </billTo> <tax> <amount>100.12</amount> <description>TAXES</description> </tax> <charge> <typeCode>ONE_TIME</typeCode> <amount>100.12</amount> <description>ONE_TIME_CHARGE</description> </charge> <charge> <typeCode>ACCESS</typeCode> <amount>100.12</amount> <description>ACCESS_CHARGE</description> </charge> <tax> <amount>100.12</amount> <description>TAXES</description> </tax> <charge> <typeCode>FEATURE</typeCode> <amount>100.12</amount> <description>FEATURE_CHARGE</description> </charge> <deduction> <amount>100.12</amount> <description>ADJUSTMENTS</description> </deduction> <charge> <typeCode>AIRTIME</typeCode> <amount>100.12</amount> <description>AIRTIME_CHARGE</description> </charge> <charge> <typeCode>LONG_DISTANCE</typeCode> <amount>100.12</amount> <description>LONG_DISTANCE_CHARGE</description> </charge> <charge> <typeCode>ROAMING</typeCode> <amount>100.12</amount> <description>ROAMING_CHARGE</description> </charge> <deduction> <amount>100.12</amount> <description>ADJUSTMENTS</description> </deduction> </billSummary> </Billing>

Expected Output: <Billing> <billSummary> <billTo> <accountNumber>130212192</accountNumber> <MSISDN>1234567890</MSISDN> </billTo> <tax> <amount>100.12</amount> <description>TAXES</description> </tax> <charge> <typeCode>ONE_TIME</typeCode> <amount>100.12</amount> <description>ONE_TIME_CHARGE</description> </charge> <charge> <typeCode>ACCESS</typeCode> <amount>100.12</amount> <description>ACCESS_CHARGE</description> </charge> <tax> <amount>100.12</amount> <description>TAXES</description> </tax> <charge> <typeCode>FEATURE</typeCode> <amount>100.12</amount> <description>FEATURE_CHARGE</description> </charge> <deduction> <amount>100.12</amount> <description>ADJUSTMENTS</description> </deduction> <charge> <typeCode>AIRTIME</typeCode> <amount>100.12</amount> <description>AIRTIME_CHARGE</description> </charge> <charge> <typeCode>LONG_DISTANCE</typeCode> <amount>100.12</amount> <description>LONG_DISTANCE_CHARGE</description> </charge> <charge> <typeCode>ROAMING</typeCode> <amount>100.12</amount> <description>ROAMING_CHARGE</description> </charge> <deduction> <amount>100.12</amount> <description>ADJUSTMENTS</description> </deduction> </billSummary> <billSummary> <billTo> <accountNumber>130212192</accountNumber> <MSISDN>1234567890</MSISDN> </billTo> <tax> <amount>100.12</amount> <description>TAXES</description> </tax> <charge> <typeCode>ONE_TIME</typeCode> <amount>100.12</amount> <description>ONE_TIME_CHARGE</description> </charge> <charge> <typeCode>ACCESS</typeCode> <amount>100.12</amount> <description>ACCESS_CHARGE</description> </charge> <tax> <amount>100.12</amount> <description>TAXES</description> </tax> <charge> <typeCode>FEATURE</typeCode> <amount>100.12</amount> <description>FEATURE_CHARGE</description> </charge> <deduction> <amount>100.12</amount> <description>ADJUSTMENTS</description> </deduction> <charge> <typeCode>AIRTIME</typeCode> <amount>100.12</amount> <description>AIRTIME_CHARGE</description> </charge> <charge> <typeCode>LONG_DISTANCE</typeCode> <amount>100.12</amount> <description>LONG_DISTANCE_CHARGE</description> </charge> <charge> <typeCode>ROAMING</typeCode> <amount>100.12</amount> <description>ROAMING_CHARGE</description> </charge> <deduction> <amount>100.12</amount> <description>ADJUSTMENTS</description> </deduction> </billSummary> </Billing>

2
Please read about posting on stackoverflow - I provided a link to some hints on good questions below. Describe exactly what you want to do, provide some short examples and an exact question. If you have comments to an answer, comment next to it. Why did you mark that question as solved if it isn't? You're asking us to help you for free in our spare time (and we will gladly do!), but please put some effort in your question before asking us to put effort into our answers. This includes eg. not breaking up fixed formatting again. - Jens Erat

2 Answers

0
votes

How about this:

doc("c:\temp\temp.xml")/
<billSummary>
  {
  for $e in billSummary/*
  order by local-name($e)
  return $e
  }
</billSummary>
0
votes

Order by node names:

<billSummary>
{
  for $i in /billSummary/*
  order by $i/name()
  return $i
}
</billSummary>

In case you want to group only items inside each bill, loop over all <billSummary/>-nodes:

for $bill in //billSummary
return
  <billSummary>
  {
    for $item in $bill/*
    order by $item/name()
    return $item
  }
  </billSummary>

If you need to wrap some node around your answer, you should be able to do it yourself; your question does not contain the information necessary.