2012-11-22 64 views
0

感谢您的快速响应。我试了两个答案。它没有按我的预期工作。请找到下面的输入和预期的输出。由于提前分组类似元素xquery

输入: <Billing> <billSummary> <billTo> </billTo> <tax> <amount> 100.12 </amount> <description></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></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>开播</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> </billTo> <tax> <amount> 100.12 </amount> <description></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></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>开播</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>

预期输出: <Billing> <billSummary> <billTo> </billTo> <tax> <amount> 100.12 </amount> <description></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></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>开播</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> </billTo> <tax> <amount> 100.12 </amount> <description></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></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>开播</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>的调整</description> </deduction> </billSummary> </Billing>

+1

请阅读张贴在计算器 - 我提供了一个链接到下面好问题的一些提示。准确描述你想要做什么,提供一些简短的例子和确切的问题。如果您对答案有评论,请在旁边留言。如果不是,你为什么将这个问题标记为解决?你要求我们在业余时间免费帮助你(我们很乐意这么做!),但请在你的问题上付出一些努力,然后再让我们努力解答我们的问题。这包括例如。没有再打破固定的格式。 –

回答

0

如何:

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

当我尝试这个解决方案时,它根据元素名称对元素进行排序,但我的要求是billSummary可以重复多次。在这种情况下,只有每个billSummary内部的元素应按以下排序 输入: 输入 – user

+0

其实,您没有。你甚至没有为此发布数据。虽然这是一个微不足道的变化,但我在答案中做了这个。请[阅读关于发布好问题](http://stackoverflow.com/questions/how-to-ask)获得更好的答案。 –

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> 

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