XSLT Forum: Displaying additional data from members on topic replies

OvalkTatt

New Member
I'm building a forum with XSLT and Symphony, and I'm having trouble getting additional member data (role/rank, avatar, for example) to be displayed next to a member's username in topic replies.Now let me show you two XML documents and then I'll explain how I'm using them and where I'm having problems. It seems long, but it's just so you have a clear picture.This is what the XML for topic replies looks like. An example containing two replies to a topic titled "Test Topic". The important bit here is \[code\]author/item\[/code\]:\[code\]<topic-replies><section id="10" handle="topic-replies">Topic Replies</section> <entry id="66"> <parent-forum> <item id="7" handle="general" section-handle="forums" section-name="Forums">General</item> </parent-forum> <parent-topic> <item id="62" handle="test-topic" section-handle="forum-topics" section-name="Forum Topics">Test Topic</item> </parent-topic> <body><p>Testing post...</p></body> <date-added time="14:44" weekday="4">2012-05-03</date-added> <author> <item id="1" handle="admin" section-handle="members" section-name="Members">Admin</item> </author> </entry> <entry id="67"> <parent-forum> <item id="7" handle="general" section-handle="forums" section-name="Forums">General</item> </parent-forum> <parent-topic> <item id="62" handle="test-topic" section-handle="forum-topics" section-name="Forum Topics">Test Topic</item> </parent-topic> <body><p>And here's a reply...?</p></body> <date-added time="22:56" weekday="5">2012-05-04</date-added> <author> <item id="1" handle="test-user-1" section-handle="members" section-name="Members">Test User 1</item> </author> </entry></topic-replies>\[/code\]And this is the XML for the registered members:\[code\]<user-list> <section id="1" handle="members">Members</section> <entry id="1"> <username handle="admin">Admin</username> <email>[email protected]</email> <role id="2"> <name handle="administrator">Administrator</name> </role> </entry> <entry id="2"> <username handle="test-user-1">Test User 1</username> <email>[email protected]</email> <role id="4"> <name handle="user">User</name> </role> </entry></user-list>\[/code\]When I code the XSLT based on the \[code\]topic-replies\[/code\] XML I can only grab the author's username. If I want more data, I'm going to have to get it from \[code\]user-list\[/code\]. This is how I do it, taking in consideration these variables:\[code\]<xsl:variable name="user-list" select="/data/user-list/entry"/><xsl:variable name="reply-author" select="/data/topic-replies/entry/author/item"/><xsl:template match="topic-replies/entry"> <ul class="profile"> <xsl:for-each select="$user-list"> <xsl:if test="username = $reply-author"> <li><a class="{role/name/@handle}" href="http://stackoverflow.com/questions/10886125/{$root}/user/{username/@handle}"><xsl:value-of select="username"/></a></li> <li><xsl:value-of select="role/name"/></li> </xsl:if> </xsl:for-each> </ul></xsl:template>\[/code\]It works, except that in each reply it fetches all the authors that have participated in the discussion instead of only displaying the designated author. The output is this:\[code\]Test Topic Testing post... Admin AdministratorRe: Test Topic And here's a reply...? Admin Administrator Test Usuer 1 User\[/code\]My question is, how do I get data from \[code\]user-list\[/code\] and insert it in a \[code\]topic-replies\[/code\] template?I'm thinking I might need to use keys, but it would be the first time I use them and I really can't think up the logic behind it. Right now, I really don't have a clue.Thanks in advance.
 
Back
Top