Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
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



Reply With Quote
  #2 (permalink)  
Old June 3rd, 2008, 06:10 PM
mhkay's Avatar
Wrox Author
Points: 18,252, Level: 58
Points: 18,252, Level: 58 Points: 18,252, Level: 58 Points: 18,252, Level: 58
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,929
Thanks: 0
Thanked 281 Times in 276 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
Reply With Quote
  #3 (permalink)  
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

Reply With Quote
  #4 (permalink)  
Old June 4th, 2008, 01:36 PM
mhkay's Avatar
Wrox Author
Points: 18,252, Level: 58
Points: 18,252, Level: 58 Points: 18,252, Level: 58 Points: 18,252, Level: 58
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,929
Thanks: 0
Thanked 281 Times in 276 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
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 04:55 PM
avoid duplicate entry of records mikersantiago Classic ASP Basics 4 February 10th, 2005 08: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



All times are GMT -4. The time now is 06:40 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.