Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Apr 2009
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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?

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    remove '/' before League or if you want use full path '/allscores/League/@league_id'

    best regards

  • #3
    New to the CF scene
    Join Date
    Apr 2009
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks. I've tried that and the output is still blank for some reason.

  • #4
    New to the CF scene
    Join Date
    Apr 2009
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    sorry, my mistake. this works well. thanks!

  • #5
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    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

  • #6
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •