[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Stuck with select distinct

Subject: Re: Stuck with select distinct
From: "Jay Bryant" <jay@xxxxxxxxxxxx>
Date: Sat, 8 Nov 2008 11:35:51 -0600
Re:  Stuck with select distinct
Hi, Mark,

You can use multiple predicates, thus:
colours/colour[. != 'Red' and . != 'Blue'][. != 'FFFFFF'][not(. = preceding-sibling::colour)]

or a single joined predicate, thus:
colours/colour[. != 'Red' and . != 'Blue' and . != 'FFFFFF' and not(. = preceding-sibling::colour)]

I threw together the following transform to demonstrate:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" indent="yes"/>

 <xsl:template match="/">

<xsl:template match="pages/page">
<xsl:copy-of select="colours/colour[. != 'Red' and . != 'Blue' and . != 'FFFFFF' and not(. = preceding-sibling::colour)]"/>


and tested it with Saxon 6.

It produced the following:

<?xml version="1.0" encoding="utf-8"?>





when run against your example (after I added an outside wrapper element to make it well-formed XML).


Jay Bryant

----- Original Message ----- From: "Mark Anderson" <mark.anderson@xxxxxxxxxxxxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Saturday, November 08, 2008 10:36 AM
Subject: Stuck with select distinct

Hi All

I'm trying to get a list of distinct items from an XML. I've done this many times using a predicate containing a preceding axis, but this one has got me stumped:


I need to return a nodeset with a list of DISTINCT colour nodes, that I can then process in a for-each element.

The other conditions for selection are:

   colour is not Red or Blue
   rgb value is not FFFFFF

I somehow need to combine the following predicates (I think)

   colours/colour[. != 'Red' and . != 'Blue']
   colours/rgb[. != 'FFFFFF']
   colours/colour[not(. = preceding-sibling::colour)]

I'm stuck with XSL 1.0 and would like to avoid using keys if possible

Any suggestions greatly appreciated



Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.