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

Finding Nodes That Match Distinct Node Value

Subject: Finding Nodes That Match Distinct Node Value
From: <Trish@xxxxxxxxxxxxxx>
Date: Thu, 8 May 2008 11:50:12 -0400
 Finding Nodes That Match Distinct Node Value
Hi:

I want to loop through an xml document and get distinct values from an
attribute and then find all sibling nodes that have that attribute
value.

I'm pulling distinct festivals based on @festival within each artist
just fine, but then I want to go back and get all of the Artist info per
festival. It seems like the code I'm using to do this should work, but
it doesn't. I can't change the organization of the xml. I'm trying not
to use keys. I only have access to XSL 1.0 for this project. The line I
need help with is:
<xsl:for-each select="//Artist[@festival = .]">

I'm guessing that the value of "." is lost because I'm beginning at the
top of the document again. I'm certain that one of you has an elegant
solution.

XML fragment (url's removed on purpose):

<?xml version="1.0" encoding="utf-8" ?>
<Festival>
  <Artist festival="2007" name="John Doe">
    <Url>http://...</Url>
    <Date>08/17/07</Date>
    <Stage>Stage Two</Stage>
  </Artist>
  <Artist festival="2007" name="Jane Doe">
    <Url>http://...</Url>
    <Date>08/15/07</Date>
    <Stage>Stage Three</Stage>
  </Artist>
  <Artist festival="2007" name="Dick Doe">
    <Url>http://...</Url>
    <Date>08/16/07</Date>
    <Stage>Stage One</Stage>
  </Artist>
  <Artist festival="2006" name="Sally Doe">
    <Url>http://...</Url>
    <Date>08/16/06</Date>
    <Stage>Stage Four</Stage>
  </Artist>
  <Artist festival="2006" name="John Q. Public">
    <Url>http://...</Url>
    <Date>08/15/06</Date>
    <Stage>Stage One</Stage>
  </Artist>
  <Artist festival="2005" name="John Smith">
    <Url>http://...</Url>
    <Date>08/17/05</Date>
    <Stage>Stage Three</Stage>
  </Artist>
  <Artist festival="2004" name="Jane Smith">
    <Url>http://...</Url>
    <Date>08/17/04</Date>
    <Stage>Stage Four</Stage>
  </Artist>
  <Artist festival="2004" name="Sally Smith">
    <Url>http://...</Url>
    <Date>08/16/04</Date>
    <Stage>Somethin' Else</Stage>
  </Artist>
  <Artist festival="2004" name="Dick Smith">
    <Url>http://...</Url>
    <Date>08/16/04</Date>
    <Stage>Stage Two</Stage>
  </Artist>
</Festival>

Code Excerpt:

<table align="center" border="0" cellpadding="3" cellspacing="1">
   <tr align="left" valign="top">
      <td>artist</td>
      <td>date</td>
      <td>stage</td>
   </tr>
   <xsl:for-each
select="//Artist/@festival[not(.=preceding::Artist/@festival)]">
      <tr>
         <td colspan="3">
            <a name="{.}"></a>
            <xsl:choose>
               <xsl:when test=". = '2007'">
                  2 0 0 7&#160;&#8226;&#160;<a href="#2006">2 0 0
6</a>&#160;&#8226;&#160;<a href="#2005">2 0 0 5</a>&#160;&#8226;&#160;<a
href="#2004">2 0 0 4</a><br />
               </xsl:when>
               <xsl:when test=". = '2006'">
                  <a href="#2007">2 0 0 7</a>&#160;&#8226;&#160;2 0 0
6&#160;&#8226;&#160;<a href="#2005">2 0 0 5</a>&#160;&#8226;&#160;<a
href="#2004">2 0 0 4</a><br />
               </xsl:when>
               <xsl:when test=". = '2005'">
                  <a href="#2007">2 0 0 7</a>&#160;&#8226;&#160;<a
href="#2006">2 0 0 6</a>&#160;&#8226;&#160;2 0 0 5&#160;&#8226;&#160;<a
href="#2004">2 0 0 4</a><br />
               </xsl:when>
               <xsl:when test=". = '2004'">
                  <a href="#2007">2 0 0 7</a>&#160;&#8226;&#160;<a
href="#2006">2 0 0 6</a>&#160;&#8226;&#160;<a href="#2005">2 0 0
5</a>&#160;&#8226;&#160;2 0 0 4<br />
               </xsl:when>
               <xsl:otherwise>
                  <a href="#2007">2 0 0 7</a>&#160;&#8226;&#160;<a
href="#2006">2 0 0 6</a>&#160;&#8226;&#160;<a href="#2005">2 0 0
5</a>&#160;&#8226;&#160;<a href="#2004">2 0 0 4</a><br />
               </xsl:otherwise>
            </xsl:choose>
         </td>
      </tr>
      <xsl:for-each select="//Artist[@festival = .]">
         <tr>
            <td><a href="{Url}"><xsl:value-of select="@name" /></a></td>
            <td><xsl:value-of select="Date" /></td>
            <td><xsl:value-of select="Stage" /></td>
         </tr>
      </xsl:for-each>
   </xsl:for-each>
</table>

Thank you so much in advance,
Trish

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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.
Email
First Name
Last Name
Company
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.