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

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 ...>

... etc ...>

I transform this to output a league table with the following xslt stylesheet.


<xsl:for-each select="league/teams/team">

<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>


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):

<clubname>Manchester City</clubname>

<clubname>Chelsea FC</clubname>
.... 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?

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

P: 3

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.

Dec 3 '06 #2

Post your reply

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