0

感谢您及时的回复。我尝试了两个答案。它没有按我的预期工作。请找到下面的输入和预期的输出。提前致谢

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>

4

2 回答 2

0

这个怎么样:

doc("c:\temp\temp.xml")/
<billSummary>
  {
  for $e in billSummary/*
  order by local-name($e)
  return $e
  }
</billSummary>
于 2012-11-22T11:32:12.190 回答
0

按节点名称排序:

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

如果您只想对每个账单中的项目进行分组,请遍历所有<billSummary/>-nodes:

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

如果你需要在你的答案周围包裹一些节点,你应该可以自己做;您的问题不包含必要的信息。

于 2012-11-22T11:27:32.860 回答