...

View Full Version : XSL - Trouble with specific item



xsl-newb
04-21-2009, 07:07 PM
Hello. I've successfully extracted and transformed everything I need from a particular XML file with the exception of one item. I have been agonizing over this for days and nothing I do seems to work. Any help would be greatly appreciated. Here is a sample of the XML code:


<?xml version="1.0" encoding="ISO-8859-1"?>
<allscores>
<League league_name="AL East" league_id="ALE">
<team team_id="141" team_name="Toronto Blue Jays">
<game_date>04/08/2009</game_date>
<game_score>11-05</game_score>
</team>

<team team_id="167" team_name="Baltimore Orioles">
<game_date>04/08/2009</game_date>
<game_score>06-09</game_score>
</team>
</League>

<League league_name="NL East" league_id="NLE">
<team team_id="211" team_name="New York Mets">
<game_date>04/08/2009</game_date>
<game_score>14-07</game_score>
</team>

<team team_id="213" team_name="Florida Marlins">
<game_date>04/08/2009</game_date>
<game_score>00-01</game_score>
</team>
</League>

</allscores>

Here is sample of my XSL code:


<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
<xsl:template match="/allscores">
<ROOT xmlns:dt="urn:schemas-microsoft-com:datatypes">
<Scores>
<xsl:for-each select="/allscores/League/team">


<LeagueID>
<xsl:value-of select="/League/@league_id"/>
</LeagueID>


<Team>
<TeamCode>
<xsl:value-of select="@team_id"/>
</TeamCode>

<TeamName>
<xsl:value-of select="@team_name"/>
</TeamName>

<Date>
<xsl:attribute name="dt:dt">string</xsl:attribute>
<xsl:value-of select="game_date"/>
</Date>
<Score>
<xsl:attribute name="dt:dt">string</xsl:attribute>
<xsl:value-of select="game_score"/>
</Score>

</Team>
</xsl:for-each>

</Scores>
</ROOT>
</xsl:template>
</xsl:stylesheet>


Everything works with the exception of league_id:


<LeagueID>
<xsl:value-of select="/League/@league_id"/>
</LeagueID>

Whether I place this snippet inside or outside of <Team>, the output remains empty each time. I have even tried the entire path (/allscores/League/@league_id) in both places but the output is still empty.

Any ideas?

oesxyl
04-21-2009, 07:14 PM
remove '/' before League or if you want use full path '/allscores/League/@league_id'

best regards

xsl-newb
04-21-2009, 07:19 PM
Thanks. I've tried that and the output is still blank for some reason.

xsl-newb
04-21-2009, 07:25 PM
sorry, my mistake. this works well. thanks!

oesxyl
04-21-2009, 07:30 PM
I'm sorry, I didn't notice that you use xsl:for-each.


<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt">

<xsl:output method="xml"/>

<xsl:template match="/allscores">
<ROOT xmlns:dt="urn:schemas-microsoft-com:datatypes">
<Scores>
<xsl:apply-templates select="League"/>
</Scores>
</ROOT>
</xsl:template>

<xsl:template match="League">
<LeagueID>
<xsl:value-of select="@league_id"/>
</LeagueID>
<xsl:apply-templates select="team"/>
</xsl:template>

<xsl:template match="team">
<Team>
<TeamCode>
<xsl:value-of select="@team_id"/>
</TeamCode>

<TeamName>
<xsl:value-of select="@team_name"/>
</TeamName>

<Date>
<xsl:attribute name="dt:dt">string</xsl:attribute>
<xsl:value-of select="game_date"/>
</Date>
<Score>
<xsl:attribute name="dt:dt">string</xsl:attribute>
<xsl:value-of select="game_score"/>
</Score>
</Team>
</xsl:template>
</xsl:stylesheet>

I didn't test this but I suppose it work. As a rule just avoid to use xsl:for-each when you don't need it.

best regards

oesxyl
04-21-2009, 07:38 PM
sorry, my mistake. this works well. thanks!
to make clear this therad, :)
removing '/' before League don't solve the problem because of xsl:for-each, which select a inner node, team
full path work instead.
Alternative but maybe to radical is to change the stylesheen to avoid xsl:for-each with what I post in my previous replay.

best regards



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum