Identifying count of elments with distinct values

Posted on 2011-04-18
Last Modified: 2012-05-11
I am new to xlst. I am trying to convert attached XML into csv file. Can somebody kindly show me that how to get count of distinct values of an element. In the attached sample xml file, I need to get  count of distinct values of element bunHCID where ProductType is Data or ProductType is voice.
Aslo, kindly let me know, if I am doing something silly in attached xslt file :)

Thanks in advance.

Question by:Yassar
    LVL 60

    Accepted Solution

    Here you go

    (I have also got rid of all the unnecessary '//' slowing down your stylesheet)
    <?xml version="1.0" encoding="UTF-8" ?>
    <xsl:stylesheet version="1.0"
        xmlns:xsl="" >
        <xsl:output method="text" indent="no"/>
        <xsl:key name="od" match="orderDetails[bunHCID > 0 and (productType = 'Voice' or productType = 'Data')]/bunHCID" use="."/>
        <xsl:template match="client"/>
        <xsl:template match="orderSubmitted/orderNumber"/>
        <xsl:template match="orderSubmitted/orderDate"/>
        <xsl:template match="orderSubmitted/dueDate"/>
        <xsl:template match="orderSubmitted/creditHold"/>
        <xsl:template match="orderSubmitted/uid"/>
        <xsl:template match="sessionId"/>
        <xsl:template match="customerInfo"/>
        <xsl:template match="orderDetails">
            <xsl:value-of select="../orderNumber"/>
            <xsl:value-of select="../orderDate"/>
            <xsl:value-of select="../uid"/>
            <xsl:for-each select="../customerInfo/*[not(starts-with(name(), 'unit'))]">
                <xsl:value-of select="."/>
            <xsl:value-of select="subCategory"/>
            <xsl:value-of select="subChoice"/>
            <!-- count added -->
            <xsl:value-of select="count(//bunHCID[generate-id() = generate-id(key('od', .)[1])])"/>

    Open in new window

    LVL 60

    Expert Comment

    by:Geert Bormans
    I based my solution on this approach

    Author Closing Comment

    Thanks For your help
    LVL 60

    Expert Comment

    by:Geert Bormans

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
    I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now