By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,361 Members | 3,185 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,361 IT Pros & Developers. It's quick & easy.

xslt - get value from a 2nd xml and replace

P: 3
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":


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.

Any suggestions as to where I am going wrong?

Regards,
DAK
Dec 3 '06 #1
Share this Question
Share on Google+
1 Reply


P: 3
Sorry,

Just to add:

I don't know if I've structured the second xml file correctly to allow this teamID-clubname swap. If not, I can change that if needed.


Again,
DAK.
Dec 3 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.