Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 17th, 2008, 06:42 AM
Authorized User
 
Join Date: Jul 2008
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSL: Display distinct values

Hi,

Could any one help how to display the distinct values using XSL 1.0,

  <Invoice>
            <InvoiceItem CT="A" >
                        <Set>
                           <Att Ty="TM" Id="LC" />
                        </Set>
            </InvoiceItem>

            <InvoiceItem CT="A" >
                        <Set>
                           <Att Ty="TM" Id="LC" />
                        </Set>
            </InvoiceItem>

            <InvoiceItem CT="S" >
                        <Set>
                            <Att Ty="TM" Id="CC" />
                        </Set>
            </InvoiceItem>
  <Invoice>

Expected output:
          LC
          CC

Output Should not be LC LC CC

XSL file :

         <Invoice>
            <xsl:for-each select="InvoiceItem[@CT='A' or @CT='S']/Set/Att[@Ty='TM']">
                        <xsl:value-of select="@Id"/>
            </xsl:for-each>
        </Invoice>

Could any one guide to get the distict values of @Id ………
 
Old July 17th, 2008, 07:00 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Use Muenchian grouping and then access the first item in each group:
Code:
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">

  <xsl:output method="text"/>

  <xsl:key name="by-id"
           match="Att[@Ty = 'TM']"
           use="@Id"/>

  <xsl:template match="/">
    <xsl:for-each select="Invoice/InvoiceItem/Set/Att[@Ty = 'TM'][generate-id() = generate-id(key('by-id', @Id)[1])]">
      <xsl:value-of select="concat(@Id, '#10;')"/>
    </xsl:for-each>
  </xsl:template>

</xsl:stylesheet>


--
  Martin Honnen
  Microsoft MVP - XML





Similar Threads
Thread Thread Starter Forum Replies Last Post
distinct data from XML using XSL Hughesie78 XSLT 5 November 20th, 2007 10:25 AM
getting distinct values from attribute markus2000 XSLT 1 June 13th, 2006 03:06 AM
count distinct values Chris Cash XSLT 3 June 8th, 2006 04:55 PM
distinct-values in Javascript Jan1 XML 2 October 10th, 2005 04:56 AM
Distinct values of data arnabghosh Access 18 September 13th, 2005 05:41 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.