XPATH SELECT Unique values


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: XPATH SELECT Unique values

  1. #1
    David Petersen Guest

    XPATH SELECT Unique values


    I have an XML data file that should be seperated into groups by the "salesgroup"
    number. What I would like to do is use a
    <xsl:for-each> on the unique group numbers and then process each group through
    an <xsl:stylesheet> that I have created. Here's the data:


    <XML id="xmldatadoc"><?xml version="1.0"?><DATA><RECORD><srid>BT01</srid><fname>TIM</fname><lname>BRECHBILL</lname><distributor>0</distributor><salesgroup>0</salesgroup><salesgroupname>Distributors</salesgroupname><totals>5673.9</totals><present>0</present
    ><thirty>0</thirty><sixty>0</sixty><ninety>5673.9</ninety></RECORD><RECORD><srid>CT01</srid><fname>TERRY</fname><lname>COOK</lname><distributor>0</distributor><salesgroup>0</salesgroup><salesgroupname>Distributors</salesgroupname><totals>92773.37</totals><

    present>0</present><thirty>0</thirty><sixty>0</sixty><ninety>92773.37</ninety></RECORD><RECORD><srid>462005</srid><fname></fname><lname>FUNDSEASY</lname><distributor>1</distributor><salesgroup>0</salesgroup><salesgroupname>Distributors</salesgroupname><tot
    als>16579.25</totals><present>0</present><thirty>0</thirty><sixty>0</sixty><ninety>16579.25</ninety></RECORD><RECORD><srid>JG01</srid><fname>GIL</fname><lname>JACKSON</lname><distributor>0</distributor><salesgroup>0</salesgroup><salesgroupname>Distributors
    </salesgroupname><totals>36198.6</totals><present>0</present><thirty>0</thirty><sixty>0</sixty><ninety>36198.6</ninety></RECORD><RECORD><srid>LT01</srid><fname>TANYA</fname><lname>LODWIG</lname><distributor>0</distributor><salesgroup>0</salesgroup><salesgr
    oupname>Distributors</salesgroupname><totals>4884.45</totals><present>0</present><thirty>0</thirty><sixty>0</sixty><ninety>4884.45</ninety></RECORD><RECORD><srid>LS01</srid><fname>SHELLI</fname><lname>LONG</lname><distributor>0</distributor><salesgroup>0</
    salesgroup><salesgroupname>Distributors</salesgroupname><totals>1170.12</totals><present>0</present><thirty>0</thirty><sixty>0</sixty><ninety>1170.12</ninety></RECORD><RECORD><srid>AD01</srid><fname>DARRYL</fname><lname>ALEXANDER</lname><distributor>0</dis
    tributor><salesgroup>12</salesgroup><salesgroupname>Inside
    Sales</salesgroupname><totals>54221.45</totals><present>0</present><thirty>0</thirty><sixty>0</sixty><ninety>54221.45</ninety></RECORD><RECORD><srid>AL01</srid><fname>LISA</fname><lname>ALLEN</lname><distributor>0</distributor><salesgroup>12</salesgroup><s
    alesgroupname>Inside
    Sales</salesgroupname><totals>40644.85</totals><present>0</present><thirty>0</thirty><sixty>0</sixty><ninety>40644.85</ninety></RECORD><RECORD><srid>BL01</srid><fname>LANCE</fname><lname>BARNETT</lname><distributor>0</distributor><salesgroup>12</salesgroup
    ><salesgroupname>Inside

    Sales</salesgroupname><totals>19193.73</totals><present>0</present><thirty>0</thirty><sixty>0</sixty><ninety>19193.73</ninety></RECORD><RECORD><srid>BB01</srid><fname>BRUCE</fname><lname>BOGEN</lname><distributor>0</distributor><salesgroup>12</salesgroup><
    salesgroupname>Inside
    Sales</salesgroupname><totals>22791.95</totals><present>0</present><thirty>0</thirty><sixty>0</sixty><ninety>22791.95</ninety></RECORD><RECORD><srid>BC01</srid><fname>CLAY</fname><lname>BOGGESS</lname><distributor>0</distributor><salesgroup>12</salesgroup>
    <salesgroupname>Inside
    Sales</salesgroupname><totals>87471.83</totals><present>0</present><thirty>0</thirty><sixty>0</sixty><ninety>87471.83</ninety></RECORD><RECORD><srid>DD01</srid><fname>DAVID</fname><lname>DAY</lname><distributor>0</distributor><salesgroup>12</salesgroup><sa
    lesgroupname>Inside
    Sales</salesgroupname><totals>3064.73</totals><present>0</present><thirty>0</thirty><sixty>0</sixty><ninety>3064.73</ninety></RECORD><RECORD><srid>KS02</srid><fname>STEPHEN</fname><lname>KLINE</lname><distributor>0</distributor><salesgroup>12</salesgroup><
    salesgroupname>Inside
    Sales</salesgroupname><totals>0</totals><present>0</present><thirty>0</thirty><sixty>0</sixty><ninety>0</ninety></RECORD><RECORD><srid>AL01</srid><fname>LISA</fname><lname>ALLEN</lname><distributor>0</distributor><salesgroup>20</salesgroup><salesgroupname>
    LaLa</salesgroupname><totals>40644.85</totals><present>0</present><thirty>0</thirty><sixty>0</sixty><ninety>40644.85</ninety></RECORD><RECORD><srid>HC01</srid><fname>CONNIE</fname><lname>HOOGENDOORN</lname><distributor>0</distributor><salesgroup>20</salesg
    roup><salesgroupname>LaLa</salesgroupname><totals>0</totals><present>0</present><thirty>0</thirty><sixty>0</sixty><ninety>0</ninety></RECORD><RECORD><srid>KD01</srid><fname>DEAN</fname><lname>KANER</lname><distributor>0</distributor><salesgroup>20</salesgr
    oup><salesgroupname>LaLa</salesgroupname><totals>947.25</totals><present>0</present><thirty>0</thirty><sixty>0</sixty><ninety>947.25</ninety></RECORD><RECORD><srid>LS02</srid><fname>SKIP</fname><lname>LETTS</lname><distributor>0</distributor><salesgroup>20
    </salesgroup><salesgroupname>LaLa</salesgroupname><totals>44326.01</totals><present>0</present><thirty>0</thirty><sixty>0</sixty><ninety>44326.01</ninety></RECORD></DATA></XML>


    and the my initial attempt at selecting the group was:



    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt">
    <xsl:template match="/">
    <table>
    <xsl:for-each select="DATA/RECORD/salesgroup">
    <tr><td><xsl:value-of select="salesgroup"/></td></tr>
    </xsl:for-each>
    </table>
    </xsl:template>
    </xsl:stylesheet>


    The problem is that I am not getting the unique numbers. Any ideas?

    Thanks

  2. #2
    Bryan Archer Guest

    Re: XPATH SELECT Unique values


    Do you mean something like this? :

    <xsl:template match="/">
    <table>
    <xsl:for-each select="DATA/RECORD[not(salesgroup=preceding-sibling::RECORD/salesgroup)]">
    <xsl:variable name="id" select="salesgroup" />
    <tr>
    <td><b>Sales Group <xsl:value-of select="$id" /></b></td>
    </tr>
    <xsl:for-each select="../RECORD[salesgroup=$id]">
    <tr>
    <td>
    <xsl:value-of select="fname" />&#xa0;<xsl:value-of select="lname"
    />
    </td>
    </tr>
    </xsl:for-each>
    </xsl:for-each>
    </table>
    </xsl:template>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center