[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] 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 • <a href="#2006">2 0 0 6</a> • <a href="#2005">2 0 0 5</a> • <a href="#2004">2 0 0 4</a><br /> </xsl:when> <xsl:when test=". = '2006'"> <a href="#2007">2 0 0 7</a> • 2 0 0 6 • <a href="#2005">2 0 0 5</a> • <a href="#2004">2 0 0 4</a><br /> </xsl:when> <xsl:when test=". = '2005'"> <a href="#2007">2 0 0 7</a> • <a href="#2006">2 0 0 6</a> • 2 0 0 5 • <a href="#2004">2 0 0 4</a><br /> </xsl:when> <xsl:when test=". = '2004'"> <a href="#2007">2 0 0 7</a> • <a href="#2006">2 0 0 6</a> • <a href="#2005">2 0 0 5</a> • 2 0 0 4<br /> </xsl:when> <xsl:otherwise> <a href="#2007">2 0 0 7</a> • <a href="#2006">2 0 0 6</a> • <a href="#2005">2 0 0 5</a> • <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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|