Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
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 June 3rd, 2008, 05:45 PM
Registered User
 
Join Date: Jun 2008
Location: Perrysburg, OH, USA.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default How Do I avoid duplicate values

Hi,

I have a xml document like this.
<root>
<S_HL>
<diag1>
   <code v="100.2">
   <code v="120.3">
 </diag1>
 <diag2>
   <code v="100.2">
   <code v="300.0">
  </diag2>
<S_HL>
I want to display distinct values using xsl like, If I see the duplicate value next time, then I shouldn't get S_HL segment.

Example:
   code : 100.2
   code: 120.3
  How do I get these values using xsl?

Note:- Plz dont provide me the links apart from solution

Thanks
Chinnu



 
Old June 3rd, 2008, 06:10 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

>Plz dont provide me the links apart from solution

Don't be impertinent. You'll get what you're given. Beggars can't be choosers.

The problem you describe is known as "grouping". In XSLT 2.0, use the xsl:for-each-group instruction. In XSLT 1.0, use the Muenchian grouping coding pattern. You will find both described in any XSLT textbook and on many tutorial sites: just google.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old June 4th, 2008, 12:08 PM
Registered User
 
Join Date: Jun 2008
Location: Perrysburg, OH, USA.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi MHKAY,

Thns for ur quick response.

Please dont misunderstand me. I am learning XSLT now. Before posting the question, I have searched the forums and found all the discussions are pointing to same link which I cant understand clearly.My intention is to put the note as to get the exact coding where I am looking for my job.

My problem is like, I have to generate nodes in destination as
/* Code */
           <L>
               <H>
                  <D>ruby</D>
                  <A>Diamond</A>
                  <B>Gold</B>
                  <S>
                     <C>LMP003</C>
                     <E>20080522</E>
                  </S>
               </H>
            </L>

/* Code */

If i see the corresponding node C value "LMP003" in source field BSTNR again in tree navigation, then it should not display the complete L node.What should I code? MY CODING IS AS FOLLOWS.

<xsl:template match="E1EDL41">
<L>
 <H>
  <D><xsl:value-of select="ancestor::E1EDL41/E1EDT13/NTANF"/></D>
  <A><xsl:value-of select="ancestor::E1EDL41/E1EDT13/BLNR"/></A>
  <B><xsl:value-of select="ancestor::E1EDL41/E1EDT13/POSR"/></B>
  <S>
    <C><xsl:value-of select="BSTNR"/></C>
    <E><xsl:value-of select="ancestor::E1EDL20/EDATE"/></E>
  </S>
 </H>
</L>
</xsl:template>

Thanks
Chinnu

 
Old June 4th, 2008, 01:36 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Firstly, you need to say whether you're using XSLT 1.0 or 2.0. Grouping is much easier in 2.0, but if you're running client-side in the browser then you're stuck with 1.0 for the time being.

Secondly, you've shown the desired output but not the input.

And you haven't shown enough of the output. You say "If i see the corresponding node C value "LMP003" in source field BSTNR again in tree navigation, then it should not display the complete L node." So what should it display? Nothing at all?

The template you've shown, matching E1EDL41, produces one L element in your output for every E1EDL41 element in your input. You want to produce one L for a set of E1EDL41 elements that have the same BSTNR value. So the grouping needs to be done one level up, where you process the parent of the E1EDL41 elements.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference




Similar Threads
Thread Thread Starter Forum Replies Last Post
how to avoid duplicate values from the xml file us balasundarrao XSLT 2 June 4th, 2014 11:56 PM
how to avoid duplicate contacts? combo box? dstein4d Access VBA 5 February 26th, 2008 05:55 PM
avoid duplicate entry of records mikersantiago Classic ASP Basics 4 February 10th, 2005 09:14 PM
avoid adding duplicate records in access/asp mikersantiago Classic ASP Basics 1 September 21st, 2004 03:24 AM
Avoid duplicate node values nambati XSLT 1 September 8th, 2004 02:41 PM





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