xsl-list
[Top] [All Lists]

RE: Outputing a node whose value appears only once

2005-07-18 22:59:45
Hi Jonathan,
  I think you need this stylesheet! As Mike suggested
we need to use Muenchian grouping technique..

<?xml version="1.0"?> 
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">
 
<xsl:output method="text" /> 

<xsl:key name="by-elem" match="a/* | c/*" use="." />
 
<xsl:template match="/root">
  <xsl:for-each select="(a/* | c/*)[generate-id() =
generate-id(key('by-elem',.)[1])][count(key('by-elem',.))
= 1]">
     <xsl:value-of select="."
/><xsl:text>&#xa;</xsl:text>
  </xsl:for-each>
</xsl:template>
 
</xsl:stylesheet>

Regards,
Mukul

--- Jonathan Marenus <jonathanmarenus(_at_)yahoo(_dot_)com>
wrote:


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(_at_)saxonica(_dot_)com> 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(_at_)yahoo(_dot_)com] 
Sent: 18 July 2005 23:35
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
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


                
____________________________________________________
Start your day with Yahoo! - make it your home page 
http://www.yahoo.com/r/hs 
 

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--