• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 309
  • 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.

  • 3
1 Solution
Geert BormansInformation ArchitectCommented:
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: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

Geert BormansInformation ArchitectCommented:
I based my solution on this approach
YassarAuthor Commented:
Thanks For your help
Geert BormansInformation ArchitectCommented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

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