XSLT:一次性计算过滤子集和完整数据集的结果
我的 xslt-fu 还是很弱。初期。
我的 XML 数据是公司、其服务提供商及其价值的列表。
我设法按服务提供商进行分组,这样我就可以看到哪些服务提供商在客户数量和总体市场价值方面拥有最大的市场份额。
这对于整个市场来说效果很好,但我也想获得“前 100 名(按价值)公司”的价值。我不知道如何添加这个。
当前的 XSLT(请参阅有关我想要添加其他数据的位置的注释):
<xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal">
<xsl:output method="html" indent="no"/>
<xsl:key name="providerkey" match="/dsQueryResponse/Rows/Row" use="@svcprovider" />
<xsl:template match="/">
<table>
<tr>
<th>Service Provider</th>
<th>Total Market value</th>
<th>No. Cos</th>
<th>Market value from top 100 cos</th>
<th>No. cos from top 100</th>
</tr>
<xsl:for-each select="/dsQueryResponse/Rows/Row[generate-id(.)=generate-id(key('providerkey',@svcprovider)[1])]">
<xsl:sort select="count(key('providerkey',@svcprovider))" order="descending" data-type="number" />
<xsl:variable name="totalvalue" select="sum(/dsQueryResponse/Rows/Row[@svcprovider=current()/@svcprovider]/@covalue)" />
<tr>
<td>
<xsl:value-of select="current()/@svcprovider"/>
</td>
<td>
<xsl:value-of select="$totalvalue" />
</td>
<td>
<xsl:value-of select="count(key('providerkey',@svcprovider))"/>
</td>
<td>
<!-- How do I get total value, but only from the top 100 companies ?? -->
</td>
<td>
<!-- How do I get total no. of companies, but only from the top 100 ?? -->
</td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
示例 XML 数据是:
<Rows>
<Row coname="client name 1" svcprovider="svc provider name 1" covalue="998" />
<Row coname="client name 2" svcprovider="svc provider name 2" covalue="1081" />
<!-- ...etc... -->
</Rows>
显然有超过 100 行。基本上我用它来计算整个市场的市场份额,并且还想计算高端市场的份额。
我希望我需要添加一个额外的排序/过滤循环,但我不确定如何嵌套它。
预先感谢
约翰
My xslt-fu is still very weak. Early days.
My XML data is a list of companies, their service provider, and their value.
I've managed to group by service provider so I can see which service providers have the most market share by number of clients, and overall market value.
This works well for the whole market, but I'd also like to get values out for the "top 100 (by value) companies" as well. I have no idea how to add this.
Current XSLT (see comments for where I would like to add additional data):
<xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal">
<xsl:output method="html" indent="no"/>
<xsl:key name="providerkey" match="/dsQueryResponse/Rows/Row" use="@svcprovider" />
<xsl:template match="/">
<table>
<tr>
<th>Service Provider</th>
<th>Total Market value</th>
<th>No. Cos</th>
<th>Market value from top 100 cos</th>
<th>No. cos from top 100</th>
</tr>
<xsl:for-each select="/dsQueryResponse/Rows/Row[generate-id(.)=generate-id(key('providerkey',@svcprovider)[1])]">
<xsl:sort select="count(key('providerkey',@svcprovider))" order="descending" data-type="number" />
<xsl:variable name="totalvalue" select="sum(/dsQueryResponse/Rows/Row[@svcprovider=current()/@svcprovider]/@covalue)" />
<tr>
<td>
<xsl:value-of select="current()/@svcprovider"/>
</td>
<td>
<xsl:value-of select="$totalvalue" />
</td>
<td>
<xsl:value-of select="count(key('providerkey',@svcprovider))"/>
</td>
<td>
<!-- How do I get total value, but only from the top 100 companies ?? -->
</td>
<td>
<!-- How do I get total no. of companies, but only from the top 100 ?? -->
</td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
Sample XML data is:
<Rows>
<Row coname="client name 1" svcprovider="svc provider name 1" covalue="998" />
<Row coname="client name 2" svcprovider="svc provider name 2" covalue="1081" />
<!-- ...etc... -->
</Rows>
Obviously there are well over 100 rows. Basically I'm using this to calculate market share across the whole of the market, and would like to also calculate for the top-end.
I expect I need to add an additional sorting/filtering loop, but I'm not sure how to go about nesting it.
Thanks in advance
John
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试如下操作:
当应用于以下 XML 文档时:
结果是:
Try something like this:
when applied on the following XML document:
the result is: