XSLT - XML 中每个元素中每个属性的总和与 for-each?
我对整个 XSLT 事物很陌生,并且我已经尝试通过几个论坛查找它,但我仍然没有找到解决我的问题的实际解决方案。
我有以下 XML:
<Cinema>
<Movie name="movie1" in="191" out="191">
<Period time="16:00:00" in="20" out="20"/>
<Period time="18:00:00" in="71" out="70"/>
<Period time="20:00:00" in="100" out="101"/>
</Movie>
<Movie name="movie2" in="105" out="105">
<Period time="16:00:00" in="13" out="13"/>
<Period time="18:00:00" in="34" out="34"/>
<Period time="20:00:00" in="58" out="58"/>
</Movie>
<Movie name="movie3" in="247" out="247">
<Period time="16:00:00" in="57" out="57"/>
<Period time="18:00:00" in="75" out="72"/>
<Period time="20:00:00" in="115" out="118"/>
</Movie>
</Cinema>
我想要获取的是每个电影时段的总访客数。 例如:
16:00h - in: 90, out: 90
18:00h - in: 180, out: 176
20:00h - in: 273, out: 277
Total - in: 543, out: 543
我尝试为每个循环嵌套,但我无法真正弄清楚如何在这种示例中使用它,因为 XSLT 不接受可更改的变量,而我实际上已经习惯了(过程编程)。
有人能为我解决这个问题吗?提前致谢!
I am new to the whole XSLT thing and I've already tried looking it up through several forums, but I still haven't found the actual solution to my problem.
I have the following XML:
<Cinema>
<Movie name="movie1" in="191" out="191">
<Period time="16:00:00" in="20" out="20"/>
<Period time="18:00:00" in="71" out="70"/>
<Period time="20:00:00" in="100" out="101"/>
</Movie>
<Movie name="movie2" in="105" out="105">
<Period time="16:00:00" in="13" out="13"/>
<Period time="18:00:00" in="34" out="34"/>
<Period time="20:00:00" in="58" out="58"/>
</Movie>
<Movie name="movie3" in="247" out="247">
<Period time="16:00:00" in="57" out="57"/>
<Period time="18:00:00" in="75" out="72"/>
<Period time="20:00:00" in="115" out="118"/>
</Movie>
</Cinema>
What I am trying to get is the total visitors of each movie period.
For example:
16:00h - in: 90, out: 90
18:00h - in: 180, out: 176
20:00h - in: 273, out: 277
Total - in: 543, out: 543
I tried nested for each loops but I couldn't really figure out how to use it in this kind of example, because XSLT doesn't accept changeable variables, which I am actually used to (procedural programming).
Does anyone have a simple solution to this problem for me? Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
sum
函数。XSTL 1.0 解决方案:
输出:
它使用 Muenchian 方法进行分组。参考:http://www.jenitennison.com/xslt/grouping/muenchian.html
参考:http://www.w3.org/TR/xpath/#path-abbrev
You can use
sum
function.XSTL 1.0 solution:
Output:
It uses Muenchian method for grouping. Reference: http://www.jenitennison.com/xslt/grouping/muenchian.html
Reference: http://www.w3.org/TR/xpath/#path-abbrev