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 Search this Thread Display Modes
  #1 (permalink)  
Old February 16th, 2009, 08:50 AM
Authorized User
Points: 153, Level: 3
Points: 153, Level: 3 Points: 153, Level: 3 Points: 153, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2009
Posts: 36
Thanks: 3
Thanked 0 Times in 0 Posts
Default removing duplicate nodes

Hi,
I'm trying to the the following
<!-- creating a variable -->
<xsl:variable name="locationCodes">
<xsl:for-each select="Output/../../../insureditems"> <xsl:variable name="code">
<xsl:call-template name="scrollLocationLink">
<xsl:with-param name="polbr" select="../POLBRR"/> </xsl:call-template>
</xsl:variable>
<xsl:variable name="occupancy">
<xsl:value-of select="OPCT"/>
</xsl:variable>
<xsl:value-of select="concat($code,'/' ,$occupancy)"/>
<xsl:if test="not(position( ) = last( ) )">
<xsl:text>#</xsl:text>
</xsl:if> </xsl:for-each>
</xsl:variable>

<!-- getting a nodeset using the tokenize function -->
<xsl:variable name="listLocationCodes" select="tokenize($locationCodes,'#') "/>

I'm trying to elimate duplicate nodes by doing the following
<xsl:variable name="listLocationCodesNoDups" select="$listLocationCodes[not( .= preceding-sibling:: *)] "/>

this is not working i'm using the xmlspy built in parser.

Anyone could assis me in solving this

Thanks
Reply With Quote
  #2 (permalink)  
Old February 16th, 2009, 09:17 AM
Friend of Wrox
Points: 6,676, Level: 34
Points: 6,676, Level: 34 Points: 6,676, Level: 34 Points: 6,676, Level: 34
Activity: 50%
Activity: 50% Activity: 50% Activity: 50%
 
Join Date: Nov 2007
Location: Germany
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

tokenize suggests you use XSLT 2.0.
If you want to remove duplicates from a sequence of strings like that returned by the tokenize function then simply use the function distinct-values http://www.w3.org/TR/xpath-functions...istinct-values
Code:
<xsl:variable name="listLocationCodesNoDups" select="distinct-values($listLocationCodes)"/>
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
Reply With Quote
  #3 (permalink)  
Old February 16th, 2009, 09:28 AM
mhkay's Avatar
Wrox Author
Points: 18,438, Level: 59
Points: 18,438, Level: 59 Points: 18,438, Level: 59 Points: 18,438, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,954
Thanks: 0
Thanked 290 Times in 285 Posts
Default

Further to Martin's response, the reason your code doesn't work is that tokenize() returns a sequence of strings (not nodes), and strings don't have preceding siblings. Only nodes have siblings.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
Reply With Quote
  #4 (permalink)  
Old February 16th, 2009, 10:19 AM
Authorized User
Points: 153, Level: 3
Points: 153, Level: 3 Points: 153, Level: 3 Points: 153, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2009
Posts: 36
Thanks: 3
Thanked 0 Times in 0 Posts
Default

martin & micheal ,
thanks for your reply.

I would like to know how i can elimate duplicate nodes if i create a node set as follows

<xsl:variable name="locationCodes">
<xsl:for-each select="Output/../../../insureditems"> <r>
<c1>
<xsl:call-template name="scrollLocationLink">
<xsl:with-param name="polbr" select="../POLBRR"/>
</xsl:call-template>
</c1>
<c2><xsl:value-of select="OPCT"/></c2>
</r>
</xsl:for-each>
</xsl:variable>


<xsl:for-each select="exslt:node-set($locationCodes)/*">
<xsl:if test="$locationCodes[not(.=preceding-sibling:: *)]">
<locCode><xsl:value-of select="c1"/></locCode>
<occupancy><xsl:value-of select="c2"/></occupancy>
</xsl:if>
</xsl:for-each>

i would like to know what is it that i'm not doing correctly

thanks
Reply With Quote
  #5 (permalink)  
Old February 16th, 2009, 10:32 AM
mhkay's Avatar
Wrox Author
Points: 18,438, Level: 59
Points: 18,438, Level: 59 Points: 18,438, Level: 59 Points: 18,438, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,954
Thanks: 0
Thanked 290 Times in 285 Posts
Default

I'm having to make guesses because you haven't shown your called template. However,

(a) exslt:node-set($locationCodes)/* selects a sequence that contains <r> elements, whose children are <c1> and <c2> elements, and in that situation, comparing the string value of each <r> element with its preceding siblings, (the string value being the concatenation of the <c1> and <c2> values), would seem a bit surprising.

(b) There's something wrong here:

<xsl:for-each select="exslt:node-set($locationCodes)/*">
<xsl:if test="$locationCodes[not(.=preceding-sibling:: *)]">

because the value of the test doesn't depend on which node you are currenly processing. I think you meant either

<xsl:for-each select="exslt:node-set($locationCodes)/*[not(.=preceding-sibling:: *)]">

or

<xsl:for-each select="exslt:node-set($locationCodes)/*">
<xsl:if test="not(.=preceding-sibling:: *)">
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
Reply With Quote
  #6 (permalink)  
Old February 16th, 2009, 10:32 AM
Friend of Wrox
Points: 6,676, Level: 34
Points: 6,676, Level: 34 Points: 6,676, Level: 34 Points: 6,676, Level: 34
Activity: 50%
Activity: 50% Activity: 50% Activity: 50%
 
Join Date: Nov 2007
Location: Germany
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Try whether
Code:
<xsl:for-each select="exslt:node-set($locationCodes)/*[not(c1 = preceding-sibling::*/cs)]">
  <locCode><xsl:value-of select="c1"/></locCode>
  <occupancy><xsl:value-of select="c2"/></occupancy>
</xsl:for-each>
works.

But I am confused as to why you make use of exslt:node-set, your original post seemed to be XSLT 2.0 which does not need that function at all and which would allow you to use xsl:for-each-group e.g.
Code:
<xsl:for-each-group select="$locationCodes/*" group-by="c1">
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
Reply With Quote
  #7 (permalink)  
Old February 16th, 2009, 10:40 AM
Authorized User
Points: 153, Level: 3
Points: 153, Level: 3 Points: 153, Level: 3 Points: 153, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2009
Posts: 36
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Thank you for both of your help.

I wanted to get a solution that works for xsl 1.0 that's why i tried the node-set method.

Thanks
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Removing duplicate entries avantikad XSLT 2 January 2nd, 2008 12:29 PM
Removing duplicate Value Row milindsaraswala Excel VBA 0 November 14th, 2007 06:11 PM
Removing duplicate nodes post-process QuickSilver002 XSLT 3 April 4th, 2007 03:47 PM
Removing the Duplicate anukagni Access 3 August 31st, 2006 12:57 AM
Removing Duplicate Fields antonides Access 2 December 1st, 2003 07:37 PM



All times are GMT -4. The time now is 11:37 PM.


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