Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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 March 6th, 2009, 07:10 PM
Registered User
 
Join Date: Mar 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default compare multiple items and get unique list?

Using MSXML 4.0, XSLT version 1.0. Producing HTML using classic ASP + XSL + an XML file.

Hello sirs, madams and gurus. I have an XML document like this:
Code:
 
<list>
<contact id="1">
<name>Steve</name>
<colors>|blue|green|yellow|</colors>
</contact>
<contact id="2">
<name>Bill</name>
<colors>|red|green|</colors>
</contact>
<contact id="3">
<name>Susan</name>
<colors>|white|green|lightgreen|</colors>
</contact>
</list>
I get one or more color names sent to the asp page, where I recieve and turn them into a XML fragment which I send to the XSL page as a parameter. The XML fragment looks like this if "blue, green" is sent to the asp page:
Code:
<palette>
<item>blue</item>
<item>green</item>
</palette>
What I'm trying to achieve is a list of the names which has one or more of the colors sent to the asp page. This is the XSL I´ve done so far (which doesn't produce exactly what I want):
Code:
<xsl:param name="paletteXML"/>
.
.
.
<xsl:apply-templates select="/list/contact"/>
.
.
.
<xsl:template match="contact">
<xsl:variable name="current_colors" select="colors"/>
<xsl:variable name="current_name" select="name"/>
<xsl:for-each select="msxsl:node-set($paletteXML)/palette/item">
<xsl:if test="contains($current_colors, concat('|',.,'|'))">
<xsl:value-of select="$current_name"/><BR />
</xsl:if>
</xsl:for-each>
</xsl:template>
This results in the following output...

Steve
Steve
Bill
Susan

...since Steve has both green and blue in his colors node. But I really want the following output:

Steve
Bill
Susan

That is - even if one person has more than one of the colors sent to the asp page, I only want that name to be listed once.
Been trying for two days, and looking at grouping etc, but I'm kind of stuck. Any help or pointer is very very much appreciated. Thanks.
/Mike
 
Old March 6th, 2009, 07:25 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You're on the right track here that "grouping" is part of the answer, but I think this one is really stretching the limits of what can be done with XSLT 1.0 (does it have to be 1.0?)

You could go for a two-pass solution in which the first pass tokenizes the colors elements into multiple elements, and the second pass does a classic Muenchian grouping.

Or you could go for a low-level recursive pass over the data, tokenizing the colors values and accumulating distinct values as you go. Not something I would fancy doing, knowing that it's so easy in 2.0:

distinct-values(//colors/tokenize(., '|'))
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old March 6th, 2009, 10:11 PM
Registered User
 
Join Date: Mar 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you very much Mr. Kay - I will look into if we can use 2.0 instead, as that solution obviousely looks a lot smarter.

A big thx, and a lot of appreciation from me.

Have a great weekend!

/Mike





Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I list multiple items on 1 job? bamajog Access 3 April 19th, 2007 03:27 PM
Unique list with two components ... asearle XSLT 7 October 9th, 2006 09:33 AM
fill dropdown list with items when parent list isaac_cm Pro PHP 1 July 10th, 2006 05:41 AM
counting unique items malekmac Access 15 November 29th, 2005 04:20 PM
Choosing Multiple Items in a List Box HenryE Access 1 July 25th, 2005 07:14 AM





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