This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: getting distinct content from list (?)
- From: Kurt George Gjerde <kurt dot gjerde at intermedia dot uib dot no>
- To: Vasu Chakkera <vasucv at hotmail dot com>
- Cc: <xsl-list at lists dot mulberrytech dot com>
- Date: Thu, 22 Aug 2002 19:53:20 +0200 (MET DST)
- Subject: Re: [xsl] getting distinct content from list (?)
- Reply-to: xsl-list at lists dot mulberrytech dot com
On Thu, 22 Aug 2002, Vasu Chakkera wrote:
> Your Problem is simple
Great.
> but without you providing the XML file, nothing much
> can be done.can you please send a snip.. of your xml so that its easu to
> sort your problem.
Sorry. Here it is.
XML:
<ming>
<users>
<user id="cynthia" email="cynthia@example.com" global-notify="yes"/>
<user id="bob" email="bob@example.com"/>
<user id="janet" email="janet@tux.example.com"/>
<user id="jack" email="jack@example.com"/>
</users>
<clients>
<client id="frontside">
<admin user="jack"/>
</client>
<client id="uptown">
<admin user="cynthia"/>
</client>
<client id="duke"/>
</clients>
<monitors>
<monitor client="frontside">
<notify user="cynthia"/>
<notify user="janet"/>
</monitor>
<monitor client="uptown">
<notify user="janet"/>
</monitor>
</monitors>
</ming>
XSL:
<xsl:template match="monitor">
<xsl:variable name="myClient" select="@client"/>
<xsl:variable name="notifyList">
<xsl:for-each select="notify/@user |
/ming/users/user[@global-notify='yes']/@id |
/ming/clients/client[@id=$myClient]/admin/@user"
>
<xsl:sort select="."/>
<xsl:variable name="pos" select="position()"/>
<xsl:choose>
<xsl:when test="last() > 1 and position()=last()"> and </xsl:when>
<xsl:when test="position() > 1">, </xsl:when>
</xsl:choose>
<xsl:value-of select="."/>
</xsl:for-each>
</xsl:variable>
<p>
Client: <xsl:value-of select="@client"/><br/>
Notify: <xsl:value-of select="$notifyList"/>
</p>
</xsl:template>
For client="frontside" this would output
"cynthia, cynthia, jack and janet"
(without sorting: "cynthia, jack, cynthia and janet").
thanks,
-kurt.
> >From: Kurt George Gjerde <kurt.gjerde@intermedia.uib.no>
> >Reply-To: xsl-list@lists.mulberrytech.com
> >To: <xsl-list@lists.mulberrytech.com>
> >Subject: [xsl] getting distinct content from list (?)
> >Date: Thu, 22 Aug 2002 16:31:10 +0200 (MET DST)
> >
> >Hi,
> >
> >The least of my xslt problems at the moment is this one (I have others
> >which I'm sure I'll come back to ;). This is probably easy
> >but I just can't see it. Here it goes.
> >
> >I have an xpath which results in a list like:
> >'cynthia', 'bob', 'janet', 'bob', 'jack', 'bob', 'jack'.
> >
> >These are user IDs collected from different locations in a document. The
> >actual xpath is:
> > notify/@user |
> > /ming/users/user[@global-notify='yes']/@id |
> > /ming/client[@id=$myClient]/admin/@user
> >
> >I need to output this as: "bob, cynthia, jack and janet".
> >Without the duplicates (sorted and xslt 1.0).
> >
> >How?
> >
> >
__________
kurt george gjerde <kurt.gjerde@intermedia.uib.no>
intermedia uib, university of bergen
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list