本文介绍了如何改善我的Muenchian分组XSLT?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
感谢 Niraj 的帮助, hr_117 我能够找到一个XSL模板,该模板可以转换该XML ...
Thanks to the help of Niraj and hr_117 I was able to arrive at an XSL template that turns this XML...
<bookings>
<entry>
<event>Christmas</event>
<attendees>2</attendees>
</entry>
<entry>
<event>Halloween</event>
<attendees>2</attendees>
</entry>
<entry>
<event>Easter</event>
<attendees>1</attendees>
</entry>
<entry>
<event>Easter</event>
<attendees>1</attendees>
</entry>
</bookings>
...进入此输出:
万圣节:1个预订
复活节:2个预订
这是我的XSL:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="data">
<xsl:apply-templates select="bookings"/>
</xsl:template>
<xsl:key name="bookings-within-period" match="bookings/entry" use="event" />
<xsl:template match="bookings">
<xsl:for-each select="entry[count(. | key('bookings-within-period', event)[1]) = 1]">
<p>
<xsl:value-of select="concat(event,': ')" />
<xsl:value-of select="count(key('bookings-within-period', event))" />
<xsl:text> booking(s)</xsl:text>
</p>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
如何获取此函数来计算attendees
的 sum ?
How can I get this function to calculate the sum of attendees
as well?
这是我需要的输出:
万圣节:1个预订,2个与会者
Halloween: 1 booking(s), 2 attendee(s)
复活节:2个预订,2个与会者
Easter: 2 booking(s), 2 attendee(s)
感谢任何可以提供帮助的人!
Thanks to anybody who can help!
推荐答案
增强的XSLT如下:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="data">
<xsl:apply-templates select="bookings"/>
</xsl:template>
<xsl:key name="bookings-within-period" match="bookings/entry" use="event" />
<xsl:template match="bookings">
<xsl:for-each select="entry[count(. | key('bookings-within-period', event)[1]) = 1]">
<p>
<xsl:value-of select="concat(event,': ')" />
<xsl:value-of select="count(key('bookings-within-period', event))" />
<xsl:text> booking(s), </xsl:text>
<xsl:value-of select="sum(key('bookings-within-period', event)/attendees)" />
<xsl:text> attendee(s)</xsl:text>
</p>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
我们有<xsl:value-of select="sum(key('bookings-within-period', event)/attendees)" />
个汇总所有与会者的地方
where we have <xsl:value-of select="sum(key('bookings-within-period', event)/attendees)" />
to sum all the attendees
这篇关于如何改善我的Muenchian分组XSLT?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!