[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] Outputing a node whose value appears only once


Subject: RE: [xsl] Outputing a node whose value appears only once
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 19 Jul 2005 06:29:55 +0100

I fear this is one of those threads where every time your question is
answered, you will change the question... perhaps you could tell us what you
are *really* trying to do.

You can find a value that is in a but not in c by a small modification to
the previous example:

 <xsl:key name="gk" match="c/*" use="."/>
 
 and testing a node
 
 <xsl:template match="a/*">
   <xsl:if test="not(key('gk', .))">
     The value is in a but not in c
   </xsl:if>
 </xsl:template>

and conversely, mutatis mutandis.

Michael Kay
http://www.saxonica.com/ 

> -----Original Message-----
> From: Jonathan Marenus [mailto:jonathanmarenus@xxxxxxxxx] 
> Sent: 19 July 2005 06:06
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: RE: [xsl] Outputing a node whose value appears only once
> 
> 
> Ok, I kind of got your point thus far. In my example,
> I had two parents, 'a' and 'c'.  How would I go about
> outputing what is in 'a' and not 'c' separately from
> outputing what is in 'c' but not 'a'.  In other words,
> I want to run my XSL to account for both the unique
> values in 'a' as well as the unique values in 'c'. 
> 
> --- Michael Kay <mike@xxxxxxxxxxxx> wrote:
> 
> > Read about Muenchian grouping at
> > http://www.jenitennison.com/xslt/grouping.
> > You can use the same idea to test whether a value is
> > unique within the file
> > (a member of a group of one) by defining the
> > grouping key
> > 
> > <xsl:key name="gk" match="b|bb|bbb" use="."/>
> > 
> > and testing a node
> > 
> > <xsl:template match="b|bb|bbb">
> >   <xsl:if test="not(key('gk', .)[2])">
> >     The value is unique
> >   </xsl:if>
> > </xsl:template>
> > 
> > Michael Kay
> > http://www.saxonica.com/
> >  
> > 
> > > -----Original Message-----
> > > From: Jonathan Marenus
> > [mailto:jonathanmarenus@xxxxxxxxx] 
> > > Sent: 18 July 2005 23:35
> > > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> > > Subject: [xsl] Outputing a node whose value
> > appears only once
> > > 
> > > 
> > > What I would like to do now is output a value that
> > > appears only once throughout the XML file. For
> > > example, if I have:
> > > 
> > > <a>
> > >    <b>value1</b>
> > >    <bb>value2</bb>
> > >    <bbb>value3</bbb>
> > > </a>
> > > <c>
> > >    <b>value1</b>
> > >    <bb>value2</bb>
> > >    <bbb>value4</bbb>
> > > </c>
> > > 
> > > From the point of view of 'a', I would want to
> > output
> > > "value3" because 'a' contains it but 'c' does not.
> > 
> > > This is assuming that the above is the entire
> > file.  I
> > > also need to output a sibling of the node which
> > does
> > > not appear more than once (like the value of a/b
> > or
> > > a/bbb).  It is also assumed that multiple
> > instances of
> > > the same value will have different parents.  This
> > is
> > > shown in the example above.
> > > 
> > > Thanks for the help.
> > > 
> > > Jonathan
> > > 
> > > __________________________________________________
> > > Do You Yahoo!?
> > > Tired of spam?  Yahoo! Mail has the best spam
> > protection around 
> > > http://mail.yahoo.com 
> > 
> > 
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around 
> http://mail.yahoo.com 


Current Thread
Keywords