frodosfoot
IS-IT--Management
Hi,
This, I'm sure, is a very simple problem.
I'm trying to use the xslt document() function to add a piece of information from a second xml file.
The main xml has a list of football teams, wins, losses, goals scored etc.
main xml:
...etc ...>
<league>
<teams>
<team>
<teamID>4573</teamID>
<round>1</round>
<points>3</points>
<wins>1</wins>
<draws>0</draws>
<losses>0</losses>
<goalsScored>4</goalsScored>
<goalsLost>0</goalsLost>
<rankTotal>3504004001008</rankTotal>
</team>
... etc ...>
I transform this to output a league table with the following xslt stylesheet:
xsl:
<xsl:for-each select="league/teams/team">
<tr>
<td><xsl:number value="position()" format="1. "/></td>
<td><xsl:value-of select="document('clubs.xml')/teams/team/teamID[@teamID=$clubname]"/></td>
<td><xsl:value-of select="round"/></td>
<td><xsl:value-of select="wins"/></td>
<td><xsl:value-of select="draws"/></td>
<td><xsl:value-of select="losses"/></td>
<td><xsl:value-of select="goalsScored"/></td>
<td><xsl:value-of select="goalsLost"/></td>
<td><xsl:value-of select="goalsScored - goalsLost"/></td>
<td><xsl:value-of select="points"/></td>
</tr>
</xsl:for-each>
In the second row of the table (above) I'm trying to replace the <teamID> in the first xml with the <clubname> from the second xml file.
The second xml acts essentially as a "lookup table": clubID (which is uselss to me and is in the xml I have to work with) and the desired clubname is in the second xml (which I have created to put the football teams name in the league table rather than its obscure ID value).
second xml (clubs.xml - to be looked up:
<teams>
<team>
<teamID>4573</teamID>
<clubname>Manchester City</clubname>
</team>
<team>
<teamID>4608</teamID>
<clubname>Chelsea FC</clubname>
</team>
.... etc ...>
As you can see, I'm not really making a good job of it. I get errors about the clubname not being resolved. I know I'm doing this wrong, but I'm not seeing the error of my ways too clearly.
If the structure of the second xml file is not conducive to such a manipulation, I can change that if needed.
Any suggestions as to where I am going wrong?
Regards,
DAK
This, I'm sure, is a very simple problem.
I'm trying to use the xslt document() function to add a piece of information from a second xml file.
The main xml has a list of football teams, wins, losses, goals scored etc.
main xml:
...etc ...>
<league>
<teams>
<team>
<teamID>4573</teamID>
<round>1</round>
<points>3</points>
<wins>1</wins>
<draws>0</draws>
<losses>0</losses>
<goalsScored>4</goalsScored>
<goalsLost>0</goalsLost>
<rankTotal>3504004001008</rankTotal>
</team>
... etc ...>
I transform this to output a league table with the following xslt stylesheet:
xsl:
<xsl:for-each select="league/teams/team">
<tr>
<td><xsl:number value="position()" format="1. "/></td>
<td><xsl:value-of select="document('clubs.xml')/teams/team/teamID[@teamID=$clubname]"/></td>
<td><xsl:value-of select="round"/></td>
<td><xsl:value-of select="wins"/></td>
<td><xsl:value-of select="draws"/></td>
<td><xsl:value-of select="losses"/></td>
<td><xsl:value-of select="goalsScored"/></td>
<td><xsl:value-of select="goalsLost"/></td>
<td><xsl:value-of select="goalsScored - goalsLost"/></td>
<td><xsl:value-of select="points"/></td>
</tr>
</xsl:for-each>
In the second row of the table (above) I'm trying to replace the <teamID> in the first xml with the <clubname> from the second xml file.
The second xml acts essentially as a "lookup table": clubID (which is uselss to me and is in the xml I have to work with) and the desired clubname is in the second xml (which I have created to put the football teams name in the league table rather than its obscure ID value).
second xml (clubs.xml - to be looked up:
<teams>
<team>
<teamID>4573</teamID>
<clubname>Manchester City</clubname>
</team>
<team>
<teamID>4608</teamID>
<clubname>Chelsea FC</clubname>
</team>
.... etc ...>
As you can see, I'm not really making a good job of it. I get errors about the clubname not being resolved. I know I'm doing this wrong, but I'm not seeing the error of my ways too clearly.
If the structure of the second xml file is not conducive to such a manipulation, I can change that if needed.
Any suggestions as to where I am going wrong?
Regards,
DAK