Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4103676
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:59:20+00:00 2026-05-20T20:59:20+00:00

My xslt-fu is still very weak. Early days. My XML data is a list

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T20:59:20+00:00Added an answer on May 20, 2026 at 8:59 pm

    Try something like this:

    <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>
    

    when applied on the following XML document:

    <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>
    

    the result is:

    <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>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

XSLT / XML: convert apostrophe to a space My XML <Name>KUEN'S INTERNATIONAL</Name> USING XSL
Using Perl's XML::LibXSLT necessitates that I use XSLT 1.0, which means that I am
I have the following code that applies a XSLT style Test.Xml.xslTransform = function(xml, xsl)
I'm teaching myself XSLT and am still trying to wrap my brain around the
I'm editing an XSLT 2.0 document in emacs and get an attribute value invalid
Im quite new to XSLT and looking at the decimal-format function im still having
I am working on XML to XML transformations through XSLT. I want to remove
I'm currently working on NMAP XML, and while my XSLT 1.0 has improved some,
I have been through many similar questions and XSLT tutorials but still I am
I'm trying to read in an XML feed using an XSLT Macro in Umbraco

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.