Я воняю в XSLT, поэтому я не уверен, как к этому приблизиться ... Я получаю фид из базы данных EQ2. XML выглядит так:
<guilds limit="1" returned="1">
<guild accounts="3" alignment="0" dateformed="1127855265" guildid="111" guildstatus="0" id="1111111111" last_update="1326986410" level="11" name="MyGuild" version="1" world="Permafrost" worldid="202">
<ranks>
<rank id="0" name="Leader"/>
<rank id="1" name="Senior Officer"/>
<rank id="2" name="Officer"/>
<rank id="3" name="Senior Member"/>
<rank id="4" name="Member"/>
<rank id="5" name="Junior Member"/>
<rank id="6" name="Initiate"/>
<rank id="7" name="Recruit"/>
</ranks>
<members>
<member dbid="123456" rank="0" name="Dude1"/>
<member dbid="123457" rank="1" name="Dude2"/>
<member dbid="123458" rank="2" name="Dude3"/>
<member dbid="123459" rank="4" name="Dude4"/>
<member dbid="123460" rank="4" name="Dude5"/>
<member dbid="123461" rank="4" name="Dude6"/>
</members>
<events/>
</guild>
</guilds>
Я пытаюсь добавить ряды в таблицу. Ниже приведен фрагмент кода XSL (версия 1), но добавление имени из ранга не работает должным образом - я знаю, что эта часть неверна:
<xsl:value-of select="rank/rank[@id=1]/@name"/>
Итак, могу ли я получить некоторую помощь, чтобы она заработала, и, может быть, идея о том, как ее сократить?
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="4.0" indent="yes"/>
<xsl:template match="/">
<table width="100%" cellspacing="0" cellpadding="0" id="eq2roster" align="center">
<thead>
<tr>
<td colspan="4" class="eq2CharacterHeader">Character</td>
<td colspan="3" class="eq2TradeskillsHeader">Tradeskills</td>
</tr>
<tr class="ForumCategoryHeader">
<th class="eq2NameHeader">Name</th>
<th class="eq2RankHeader">Rank</th>
<th class="eq2ClassHeader">Class</th>
<th class="eq2LevelHeader">Level</th>
<th class="eq2ArtisanHeader">Artisan</th>
<th class="eq2ArtisanLevelHeader">Level</th>
<th class="eq2SecondaryHeader">Secondary</th>
</tr>
</thead>
<tbody>
<xsl:for-each select="guilds/guild/members/member">
<xsl:if test="@id > 1">
<tr>
<td class="eq2Name">
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:text>http://eq2players.station.sony.com/</xsl:text>
<xsl:value-of select="concat(normalize-space(/guilds/guild/@world), '/')"/>
<xsl:value-of select="concat(normalize-space(@name), '/')"/>
</xsl:attribute>
<xsl:attribute name="target">
<xsl:text>_blank</xsl:text>
</xsl:attribute>
<xsl:value-of select="normalize-space(@name)"/>
</xsl:element>
</td>
<xsl:element name="td">
<xsl:attribute name="class">
<xsl:text>eq2Rank eq2rank-</xsl:text>
<xsl:value-of select="translate(normalize-space(guild/@rank),' ','')"/>
</xsl:attribute>
<xsl:choose>
<xsl:when test="member/@rank = 1"><span class = "rank1"><xsl:value-of select="ranks/rank[@id=1]/@name"/></span></xsl:when>
<xsl:when test="member/@rank = 2"><span class = "rank2"><xsl:value-of select="ranks/rank[@id=2]/@name"/></span></xsl:when>
<xsl:when test="member/@rank = 3"><span class = "rank3"><xsl:value-of select="ranks/rank[@id=3]/@name"/></span></xsl:when>
<xsl:when test="member/@rank = 4"><span class = "rank4"><xsl:value-of select="ranks/rank[@id=4]/@name"/></span></xsl:when>
<xsl:when test="member/@rank = 5"><span class = "rank5"><xsl:value-of select="ranks/rank[@id=5]/@name"/></span></xsl:when>
<xsl:when test="member/@rank = 6"><span class = "rank6"><xsl:value-of select="ranks/rank[@id=6]/@name"/></span></xsl:when>
<xsl:when test="member/@rank = 7"><span class = "rank7"><xsl:value-of select="ranks/rank[@id=7]/@name"/></span></xsl:when>
</xsl:choose>
</xsl:element>
<xsl:element name="td">
<xsl:attribute name="class">
<xsl:text>eq2Class eq2</xsl:text>
<xsl:value-of select="translate(normalize-space(type/@class),' ','')"/>
</xsl:attribute>
<xsl:value-of select="type/@class"/>
</xsl:element>
<td class="eq2level"><xsl:value-of select="type/@level"/></td>
<xsl:element name="td">
<xsl:attribute name="class">
<xsl:text>eq2ArtisanClass eq2</xsl:text>
<xsl:value-of select="translate(normalize-space(tradeskills/tradeskill/@class),' ','')"/>
</xsl:attribute>
<xsl:value-of select="tradeskills/tradeskill/@class"/>
</xsl:element>
<td class="eq2ArtisanLevel"><xsl:value-of select="tradeskills/tradeskill/@level"/></td>
<xsl:element name="td">
<xsl:attribute name="class">
<xsl:text>eq2Secondary eq2</xsl:text>
<xsl:value-of select="translate(normalize-space(secondarytradeskills/secondarytradeskill/@name),' ','')"/>
</xsl:attribute>
<xsl:value-of select="secondarytradeskills/secondarytradeskill/@name"/>
</xsl:element>
</tr>
</xsl:if>
</xsl:for-each>
</tbody>
</table>
</xsl:template>
</xsl:stylesheet>