p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   XSLT (http://p2p.wrox.com/forumdisplay.php?f=86)
-   -   How Do I avoid duplicate values (http://p2p.wrox.com/showthread.php?t=68576)

xsltier June 3rd, 2008 05:45 PM

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




mhkay June 3rd, 2008 06:10 PM

>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

xsltier June 4th, 2008 12:08 PM

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


mhkay June 4th, 2008 01:36 PM

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


All times are GMT -4. The time now is 02:34 PM.

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