Grouping the inner loops but getting “ task fail at one test ”: XSLT

thomas.joy

New Member
I need a help to get an accurate output. I worked on an xml with the help of the code provided by Sean B. Durkin for the following Input xml. I changed the code to get a desired output i need, yet i have a problem in getting ACCURATE OUTPUT. Help me where i am going wrong and in the the CODE.When i debug i could locate that the value for "indoor" is not recognizing at "game_no"123 and "group" 1Input XML File: \[code\]<?xml version="1.0" encoding="UTF-8"?><t><Games> <Game_no>123</Game_no> <Group>1</Group> <Name>game.outdoor</Name> <Value>Golf</Value> </Games> <Games> <Game_no>123</Game_no> <Group>1</Group> <Name>game.indoor</Name> <Value>Chess</Value> </Games> <Games> <Game_no>223</Game_no> <Group>1</Group> <Name>games.outdoor</Name> <Value>Soccer</Value> </Games> <Games> <Game_no>223</Game_no> <Group>2</Group> <Name>games.indoor</Name> <Value>Golf</Value> </Games> <Games> <Game_no>223</Game_no> <Group>1</Group> <Name>games.outdoor</Name> <Value>Batminton</Value> </Games> <Games> <Game_no>123</Game_no> <Group>1</Group> <Name>ga.outdoor</Name> <Value>tennis</Value> </Games><Games> <Game_no>123</Game_no> <Group>1</Group> <Name>today</Name> <Value>value returning with no'.'</Value> </Games> <Games> <Game_no>123</Game_no> <Group>1</Group> <Name>indoor</Name> <Value>value returning with same Group 123 and game_no 1</Value> </Games> <Games> <Game_no>123</Game_no> <Group>2</Group> <Name>outdoor</Name> <Value>value returning with different Group 2</Value> </Games> <Games> <Game_no>323</Game_no> <Group>2</Group> <Name>outdoor</Name> <Value>value returning with different Game_no 323</Value> </Games> </t> \[/code\]The Above input XML have an element "Games" in which if i have same values "Game_no" & "Group" for following nodes then i could make an desired output for element "Name" when "." is there. But if i have the same value for each node at "Game_no" & "Group" i could not achieve the output with no "." at element "Name". I shall place my desired output and the output i am getting. along with the code.Help Needed why i cant achieve that.XSL FILE CODE I modified as per my intended output:\[code\]<xsl:stylesheet version="1.0" xmlns:xsl='http://www.w3.org/1999/XSL/Transform' xmlns:ext="http://exslt.org/common" exclude-result-prefixes="ext"><xsl:key name="gamekey" match="Games" use="Game_no"/><xsl:key name="game-group" match="Games" use="concat(substring-before(Name,'.'),'|',Game_no,'|',Group)"/><xsl:template match="/"> <Holiday> <xsl:for-each select="//t/Games[generate-id(.) = generate-id(key('gamekey', Game_no)[1])] "> <Weekend> <xsl:variable name="var1" select="Game_no"/> <xsl:apply-templates select="//t/Games[generate-id(.) = generate-id( key('game-group', concat( substring-before(Name ,'.'),'|',$var1,'|',Group))[1])] [substring-before(Name ,'.')or not(Name/*)] "/> <xsl:apply-templates select="key('game-group','||')/self::Games"/> </Weekend> </xsl:for-each> </Holiday></xsl:template><xsl:template match="Games [ substring-before(Name,'.') != '']"> <xsl:element name="{substring-before(Name,'.')}"> <xsl:for-each select="key('game-group', concat( substring-before(Name,'.'),'|',Game_no,'|',Group))"> <xsl:element name="{substring-after(Name,'.')}"> <xsl:value-of select="Value"/> </xsl:element> </xsl:for-each> </xsl:element></xsl:template><xsl:template match="Games [ substring-before(Name,'.') = '']"> <xsl:element name="{Name}"> <xsl:value-of select="Value"/> </xsl:element></xsl:template>\[/code\]Output I am Getting:\[code\]<?xml version="1.0" encoding="UTF-8"?><Holiday><Weekend> <game> <outdoor>Golf</outdoor> <indoor>Chess</indoor> </game> <ga> <outdoor>tennis</outdoor> </ga> <today>value returning with no'.'</today> <outdoor>value returning with different Group 2</outdoor></Weekend><Weekend> <games> <outdoor>Soccer</outdoor> <outdoor>Batminton</outdoor> </games> <games> <indoor>Golf</indoor> </games></Weekend><Weekend> <outdoor>value returning with different Game_no 323</outdoor></Weekend></Holiday>\[/code\]Output Desired:\[code\]<?xml version="1.0" encoding="UTF-8"?><Holiday><Weekend> <game> <outdoor>Golf</outdoor> <indoor>Chess</indoor> </game> <ga> <outdoor>tennis</outdoor> </ga> <today>value returning with no'.'</today> <indoor>value returning with same Group 123 and game_no 1</indoor> <outdoor>value returning with different Group 2</outdoor></Weekend><Weekend> <games> <outdoor>Soccer</outdoor> <outdoor>Batminton</outdoor> </games> <games> <indoor>Golf</indoor> </games></Weekend><Weekend> <outdoor>value returning with different Game_no 323</outdoor></Weekend></Holiday>\[/code\]Note: Question Looks similar but i am a learner trying every way to modify the innerl loops. Help is appreciated. I am glad if i could get know why one of the Node is eleminating.
 
Back
Top