Go Back   CodingForums.com > :: Client side development > XML

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-21-2009, 06:07 PM   PM User | #1
xsl-newb
New to the CF scene

 
Join Date: Apr 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
xsl-newb is an unknown quantity at this point
XSL - Trouble with specific item

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:

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:

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:

Code:
<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?
xsl-newb is offline   Reply With Quote
Old 04-21-2009, 06:14 PM   PM User | #2
oesxyl
Master Coder


 
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
oesxyl is a jewel in the roughoesxyl is a jewel in the roughoesxyl is a jewel in the rough
remove '/' before League or if you want use full path '/allscores/League/@league_id'

best regards
oesxyl is offline   Reply With Quote
Old 04-21-2009, 06:19 PM   PM User | #3
xsl-newb
New to the CF scene

 
Join Date: Apr 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
xsl-newb is an unknown quantity at this point
Thanks. I've tried that and the output is still blank for some reason.
xsl-newb is offline   Reply With Quote
Old 04-21-2009, 06:25 PM   PM User | #4
xsl-newb
New to the CF scene

 
Join Date: Apr 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
xsl-newb is an unknown quantity at this point
sorry, my mistake. this works well. thanks!
xsl-newb is offline   Reply With Quote
Old 04-21-2009, 06:30 PM   PM User | #5
oesxyl
Master Coder


 
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
oesxyl is a jewel in the roughoesxyl is a jewel in the roughoesxyl is a jewel in the rough
I'm sorry, I didn't notice that you use xsl:for-each.

Code:
<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 is offline   Reply With Quote
Old 04-21-2009, 06:38 PM   PM User | #6
oesxyl
Master Coder


 
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
oesxyl is a jewel in the roughoesxyl is a jewel in the roughoesxyl is a jewel in the rough
Quote:
Originally Posted by xsl-newb View Post
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
oesxyl is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:23 AM.


Advertisement
Log in to turn off these ads.