0

我的 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 行。基本上我用它来计算整个市场的市场份额,也想计算高端市场。

我希望我需要添加一个额外的排序/过滤循环,但我不确定如何嵌套它。

提前致谢

约翰

4

1 回答 1

1

尝试这样的事情:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:msxsl="urn:schemas-microsoft-com:xslt"
 exclude-result-prefixes="msxsl">
    <xsl:output method="html" indent="yes"/>
    <xsl:param name="pTopNumber" select="3"/>

    <xsl:key name="providerkey"
        match="/dsQueryResponse/Rows/Row" use="@svcprovider" />

    <xsl:variable name="vrtfTopCompanies">
     <xsl:for-each select="/*/*/Row">
       <xsl:sort select="covalue"
            data-type="number" order="descending"/>
       <xsl:if test="not(position() > $pTopNumber)">
        <xsl:copy-of select="."/>
       </xsl:if>
     </xsl:for-each>
    </xsl:variable>

    <xsl:variable name="vTopRows"
         select="msxsl:node-set($vrtfTopCompanies)/*"/>

    <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 ?? -->
                        <xsl:value-of select="sum($vTopRows[@svcprovider=current()/@svcprovider]/@covalue)"/>
                    </td>
                    <td>
                        <!-- How do I get total no. of companies, but only from the top 100 ?? -->
                        <xsl:value-of select="count(key('providerkey',@svcprovider)[@coname = $vTopRows/@coname])"/>
                    </td>
                </tr>
            </xsl:for-each>
        </table>
    </xsl:template>
</xsl:stylesheet>

当应用于以下 XML 文档时

<dsQueryResponse>
    <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" />
        <Row coname="client name 3" svcprovider="svc provider name 3" covalue="998" />
        <Row coname="client name 4" svcprovider="svc provider name 4" covalue="2081" />
        <Row coname="client name 5" svcprovider="svc provider name 5" covalue="3998" />
        <Row coname="client name 2" svcprovider="svc provider name 2" covalue="1081" />
        <Row coname="client name 1" svcprovider="svc provider name 1" covalue="998" />
        <Row coname="client name 2" svcprovider="svc provider name 2" covalue="1081" />
        <Row coname="client name 1" svcprovider="svc provider name 1" covalue="998" />
        <Row coname="client name 2" svcprovider="svc provider name 2" covalue="1081" />
    </Rows>
</dsQueryResponse>

结果是

<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>
    <tr>
        <td>svc provider name 2</td>
        <td>4324</td>
        <td>4</td>
        <td>1081</td>
        <td>4</td>
    </tr>
    <tr>
        <td>svc provider name 1</td>
        <td>2994</td>
        <td>3</td>
        <td>998</td>
        <td>3</td>
    </tr>
    <tr>
        <td>svc provider name 3</td>
        <td>998</td>
        <td>1</td>
        <td>998</td>
        <td>1</td>
    </tr>
    <tr>
        <td>svc provider name 4</td>
        <td>2081</td>
        <td>1</td>
        <td>0</td>
        <td>0</td>
    </tr>
    <tr>
        <td>svc provider name 5</td>
        <td>3998</td>
        <td>1</td>
        <td>0</td>
        <td>0</td>
    </tr>
</table>
于 2011-03-16T13:42:45.850 回答