xml - XSLT Forum: Displaying additional data from members on topic replies -
i'm building forum xslt , symphony, , i'm having trouble getting additional member data (role/rank, avatar, example) displayed next member's username in topic replies.
now let me show 2 xml documents , i'll explain how i'm using them , i'm having problems. seems long, it's have clear picture.
this xml topic replies looks like. example containing 2 replies topic titled "test topic". important bit here author/item:
<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 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> and xml registered members:
<user-list> <section id="1" handle="members">members</section> <entry id="1"> <username handle="admin">admin</username> <email>admin@email.com</email> <role id="2"> <name handle="administrator">administrator</name> </role> </entry> <entry id="2"> <username handle="test-user-1">test user 1</username> <email>test.user.1@email.com</email> <role id="4"> <name handle="user">user</name> </role> </entry> </user-list> when code xslt based on topic-replies xml can grab author's username. if want more data, i'm going have user-list. how it, taking in consideration these variables:
<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="{$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> it works, except in each reply fetches authors have participated in discussion instead of displaying designated author. output this:
test topic testing post... admin administrator re: test topic , here's reply...? admin administrator test usuer 1 user my question is, how data user-list , insert in topic-replies template?
i'm thinking might need use keys, first time use them , can't think logic behind it. right now, don't have clue.
thanks in advance.
the reason happening user-list , reply-author variables contain entries in user-list , items in topic-replies.
instead of repeating on every user in list, try using user entry of author of item:
<xsl:template match="topic-replies/entry"> <xsl:variable name="authorentry" select="$user-list[username/@handle = current()/author/item/@handle]"/> <ul class="profile"> <li> <a class="{$authorentry/role/name/@handle}" href="{$root}/user/{$authorentry/username/@handle}"> <xsl:value-of select="$authorentry/username"/> </a> </li> <li> <xsl:value-of select="$authorentry/role/name"/> </li> </ul> </xsl:template> here's complete example reference:
xml input
<data> <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 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> <user-list> <section id="1" handle="members">members</section> <entry id="1"> <username handle="admin">admin</username> <email>admin@email.com</email> <role id="2"> <name handle="administrator">administrator</name> </role> </entry> <entry id="2"> <username handle="test-user-1">test user 1</username> <email>test.user.1@email.com</email> <role id="4"> <name handle="user">user</name> </role> </entry> </user-list> </data> xslt 1.0
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output indent="yes"/> <xsl:strip-space elements="*"/> <xsl:variable name="root" select="'rootvariable'"/> <xsl:variable name="user-list" select="/data/user-list/entry"/> <xsl:template match="node()|@*"> <xsl:apply-templates select="node()|@*"/> </xsl:template> <xsl:template match="/"> <html> <xsl:apply-templates/> </html> </xsl:template> <xsl:template match="topic-replies/entry"> <xsl:variable name="authorentry" select="$user-list[username/@handle = current()/author/item/@handle]"/> <ul class="profile"> <li> <a class="{$authorentry/role/name/@handle}" href="{$root}/user/{$authorentry/username/@handle}"> <xsl:value-of select="$authorentry/username"/> </a> </li> <li> <xsl:value-of select="$authorentry/role/name"/> </li> </ul> </xsl:template> </xsl:stylesheet> html output
<html> <ul class="profile"> <li><a class="administrator" href="rootvariable/user/admin">admin</a></li> <li>administrator</li> </ul> <ul class="profile"> <li><a class="user" href="rootvariable/user/test-user-1">test user 1</a></li> <li>user</li> </ul> </html>
Comments
Post a Comment