First time posting and of course I am sure it is something that has been answered 100 times but for some reason I just cant find the answer :)
First off here is the structure of the xml:
Expand|Select|Wrap|Line Numbers
- <Stats>
- <Structure>
- <Column DisplayName="GP" FieldName="GamesPlayed" Priority="1" />
- <Column DisplayName="G" FieldName="Goals" Priority="2" />
- <Column DisplayName="A" FieldName="Assists" Priority="3" />
- <Column DisplayName="PTS" FieldName="Points" Priority="4" />
- </Structure>
- <Players>
- <Player Row="1" Rank="1" Name="Jobs, Steve" GamesPlayed="33" Goals="8" Assists="3" Points="11" />
- <Player Row="2" Rank="1" Name="Gate, Bill" GamesPlayed="33" Goals="8" Assists="9" Points="17" />
- <Player Row="3" Rank="1" Name="Ballmer, Steve" GamesPlayed="33" Goals="5" Assists="12" Points="17" />
- <Player Row="4" Rank="1" Name="Jordan, Mike" GamesPlayed="33" Goals="3" Assists="12" Points="15" />
- <Player Row="5" Rank="1" Name="Cent, 50" GamesPlayed="33" Goals="0" Assists="6" Points="6" />
- </Players>
- </Stats>
I am using the "Structure" element to build the column headers of the table.
This is where I am coming up with the problem...
To make the data cells, I thought the best thing to do would be to loop through the "Structure" elem for each Player in the Players element. The problem is how to dynamically call the attributes of the current Player element.
Here is the XSLT:
Expand|Select|Wrap|Line Numbers
- <?xml version="1.0" encoding="utf-8"?>
- <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
- >
- <xsl:output method="xml" indent="yes"/>
- <xsl:template match="/">
- <xsl:apply-templates select="Stats"></xsl:apply-templates>
- </xsl:template>
- <xsl:template match="Stats">
- <table>
- <xsl:apply-templates select="Structure"></xsl:apply-templates>
- <xsl:apply-templates select="Players"></xsl:apply-templates>
- </table>
- </xsl:template>
- <xsl:template match="Structure">
- <tr>
- <th>Row</th>
- <th>Rank</th>
- <th>Name</th>
- <xsl:apply-templates select="Column"></xsl:apply-templates>
- </tr>
- </xsl:template>
- <xsl:template match="Column">
- <th>
- <xsl:value-of select="@DisplayName" />
- </th>
- </xsl:template>
- <xsl:template match="Players">
- <xsl:apply-templates select="Player"></xsl:apply-templates>
- </xsl:template>
- <xsl:template match="Player">
- <xsl:variable name="player" select="."/>
- <tr>
- <th>
- <xsl:value-of select="@Row" />
- </th>
- <th>
- <xsl:value-of select="@Rank" />
- </th>
- <th>
- <xsl:value-of select="@Name" />
- </th>
- <xsl:for-each select="//Stats/Structure/Column">
- <xsl:variable name="column" select="@FieldName"/>
- <td>
- <!--
- HERE IS THE PROBLEM
- I have tried a bunch of different things... but this is the last thing i tried
- -->
- <xsl:value-of select="concat($player, '/@", @FieldName />
- </td>
- </xsl:for-each>
- </tr>
- </xsl:template>
- </xsl:stylesheet>
Thanks in advance!!!
Andrew