如何使用 XSLT 1.0 对 XMl 进行排序?
我正在寻找一个 XSL 来按一个节点对 XML 进行排序和分组,并按另一个节点进行求和。我将不得不使用 XSLT 1.0。
这是我的 XML。 排序后,我需要对新的 XML 进行排序并按
进行分组,并且应为每个组对所有
进行求和。我正在寻找用于此任务的 XSL。任何帮助表示赞赏。排序后,新的 XML 应该只有三个按
升序排序的节点。所有
必须添加在一起。
这是我的 XML:
<Transactions>
<Transaction>
<TransCode>0008</TransCode>
<TransType>Purchase</TransType>
<TransAmt>12.30</TransAmt>
</Transaction>
<Transaction>
<TransCode>0002</TransCode>
<TransType>Cash</TransType>
<TransAmt>26.00</TransAmt>
</Transaction>
<Transaction>
<TransCode>0008</TransCode>
<TransType>Purchase</TransType>
<TransAmt>25.00</TransAmt>
</Transaction>
<Transaction>
<TransCode>0015</TransCode>
<TransType>FinanceCharge</TransType>
<TransAmt>25.00</TransAmt>
</Transaction>
<Transaction>
<TransCode>0002</TransCode>
<TransType>Cash</TransType>
<TransAmt>50.00</TransAmt>
</Transaction>
<Transaction>
<TransCode>0008</TransCode>
<TransType>Purchase</TransType>
<TransAmt>40.00</TransAmt>
</Transaction>
</Transactions>
I'm looking for an XSL to sort and group an XML by a node and sum by another node. I will have to use XSLT 1.0.
Here is my XML.
After sorting I need to have a new XML sorted and Grouped by <TransCode>
, and all <TransAmt>
should be summed for each group. I'm looking for the XSL for this task. Any help is appreciated. After sorting new XML should have only three nodes sorted in ascending order of <TransCode>
. All the <TransAmt>
must be added together.
Here is my XML:
<Transactions>
<Transaction>
<TransCode>0008</TransCode>
<TransType>Purchase</TransType>
<TransAmt>12.30</TransAmt>
</Transaction>
<Transaction>
<TransCode>0002</TransCode>
<TransType>Cash</TransType>
<TransAmt>26.00</TransAmt>
</Transaction>
<Transaction>
<TransCode>0008</TransCode>
<TransType>Purchase</TransType>
<TransAmt>25.00</TransAmt>
</Transaction>
<Transaction>
<TransCode>0015</TransCode>
<TransType>FinanceCharge</TransType>
<TransAmt>25.00</TransAmt>
</Transaction>
<Transaction>
<TransCode>0002</TransCode>
<TransType>Cash</TransType>
<TransAmt>50.00</TransAmt>
</Transaction>
<Transaction>
<TransCode>0008</TransCode>
<TransType>Purchase</TransType>
<TransAmt>40.00</TransAmt>
</Transaction>
</Transactions>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
此转换:
应用于提供的 XML 文档时:
产生所需的正确结果:
请注意:
使用按键可以轻松高效地求和每次转码。
身份规则用于按原样复制大多数元素,并被匹配输出中不同元素的模板覆盖。
This transformation:
when applied on the provided XML document:
produces the wanted, correct result:
Do note:
The Muenchian method for grouping is used.
The use of keys allows for easy and efficient summation per transcode.
The identity rule is used to copy as-is most elements and is overridden by templates matching elements that will be different in the output.
XSL 内置了通过
元素,并使用 XPathsum
< /a> 函数。XSLT 1.0 中支持两者。
您在使用这些产品时遇到了哪些问题?
XSL has built in sorting through the
<xsl:sort>
element, and summing using the XPathsum
function.Both are supported in XSLT 1.0.
What are the issues you are having using these?