• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 306
  • Last Modified:

Identifying count of elments with distinct values

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.



Sample-File.XML
XSLTFile1.xslt.txt
0
Yassar
Asked:
Yassar
  • 3
1 Solution
 
Geert BormansCommented:
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="http://www.w3.org/1999/XSL/Transform" >
    <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:text>|</xsl:text>
        <xsl:value-of select="../orderDate"/>
        <xsl:text>|</xsl:text>
        <xsl:value-of select="../uid"/>
        <xsl:text>|</xsl:text>
        <xsl:for-each select="../customerInfo/*[not(starts-with(name(), 'unit'))]">
            <xsl:value-of select="."/>
            <xsl:text>|</xsl:text>
        </xsl:for-each>
        <xsl:value-of select="subCategory"/>
        <xsl:text>|</xsl:text>
        <xsl:value-of select="subChoice"/>
        <xsl:text>|</xsl:text>
        <!-- count added -->
        <xsl:value-of select="count(//bunHCID[generate-id() = generate-id(key('od', .)[1])])"/>

    </xsl:template>
</xsl:stylesheet>

Open in new window

0
 
Geert BormansCommented:
I based my solution on this approach
http://www.jenitennison.com/xslt/grouping/muenchian.xml
0
 
YassarAuthor Commented:
Thanks For your help
0
 
Geert BormansCommented:
welcome
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now