XSL Transformation Issue

Fiendycyday

New Member
Hi I was working on this code, but Iam getting some issues. Can some one help me in solving this problem. I worked on the xsl code,but I am new on the XSL coding front. So any help on solving this issue will be appreciated.Input XML:\[code\] <test_message> <test_body> <AutoList> <AutoItem> <AutoPoint> <Name>software.prog_name</Name> <ValueTarget>JAVA</ValueTarget> </AutoPoint> <AutoPoint> <Name>software.prog_rev</Name> <ValueTarget>1</ValueTarget> </AutoPoint> <AutoPoint> <Name>software.sw_product_id</Name> <ValueTarget>1000</ValueTarget> </AutoPoint> <AutoPoint> <Name>software.limits_file_name</Name> <ValueTarget>limits.txt</ValueTarget> </AutoPoint> <AutoPoint> <Name>software.limits_file_rev</Name> <ValueTarget>2</ValueTarget> </AutoPoint> <AutoPoint> <Name>hw_exp.class</Name> <ValueTarget>Car</ValueTarget> </AutoPoint> <AutoPoint> <Name>hw_exp.type</Name> <ValueTarget>B</ValueTarget> </AutoPoint> <AutoPoint> <Name>hw_exp.rev</Name> <ValueTarget>32</ValueTarget> </AutoPoint> <AutoPoint> <Name>prompt_id</Name> <ValueTarget>100</ValueTarget> </AutoPoint> </AutoItem> <AutoParam> <Profile>Profile 1</Profile> <SubGroup>1</SubGroup> <Name>software.prog_name</Name> <Value>JAVA</ValueTarget> </AutoParam> <AutoParam> <Profile>Profile 1</Profile> <SubGroup>1</SubGroup> <Name>software.sw_product_id</Name> <Value>1000</ValueTarget> </AutoParam> <AutoParam> <Profile>Profile 1</Profile> <SubGroup>2</SubGroup> <Name>hw_exp.class</Name> <Value>Animal</Value> </AutoParam> <AutoParam> <Profile>Profile 1</Profile> <SubGroup>2</SubGroup> <Name>hw_exp.type</Name> <Value>B</Value> </AutoParam> <AutoParam> <Profile>Profile 1</Profile> <SubGroup>3</SubGroup> <Name>hw_exp.class</Name> <Value>Flight</Value> </AutoParam> <AutoParam> <Profile>Profile 1</Profile> <SubGroup>3</SubGroup> <Name>hw_exp.type</Name> <Value>E</Value> </AutoParam> <AutoParam> <Profile>Profile 1</Profile> <SubGroup>3</SubGroup> <Name>hw_exp.rev</Name> <Value>1</Value> </AutoParam> <AutoParam> <Profile>Profile 2</Profile> <SubGroup>1</SubGroup> <Name>software.sw_product_id</Name> <Value>1000</ValueTarget> </AutoParam> </AutoList> </test_body> </test_message>\[/code\]Expected Output XML:\[code\] <test_message> <test_body> <auto_level> <auto_profile> <software> <prog_name>JAVA</prog_name> <prog_rev>1</prog_rev> <sw_product_id>1000</sw_product_id> < limits_file_name>limits.txt</limits_file_name> <limits_file_rev>2</limits_file_rev> </software> <hw_exp> <class>Car</class> <type>B</type> <rev>32</rev> </hw_exp> <prompt_id>100</prompt_id> </auto_profile> <auto_profile> <software> <prog_name>JAVA</prog_name> <sw_product_id>1000</sw_product_id> </software> <hw_exp> <class>Animal</class> <type>B</type> </hw_exp> <hw_exp> <class>Flight</class> <type>E</type> <rev>1</rev> </hw_exp> </auto_profile> <auto_profile> <software> <sw_product_id>1000</sw_product_id> </software> </auto_profile> </auto_level> </test_body> </test_message>\[/code\]XSL I worked on:\[code\]<xsl:key name="kDataPointBychildName" match="DataPoint" use="name(Name/*[1])"/> <xsl:variable name="vrtfPass1"> <xsl:apply-templates/> </xsl:variable> <xsl:apply-templates mode="pass2" select="ext:node-set($vrtfPass1)/* [generate-id() = generate-id(key('kDataPointBychildName', name(Name/*[1]))[1]) ] "/> </xsl:template> <xsl:template match="AutoPoint"> <AutoPoint> <Name> <xsl:element name="{substring-before(Name, '.')}"> <xsl:element name="{substring-after(Name, '.')}"> <xsl:value-of select="ValueTarget"/> </xsl:element> </xsl:element> </Name> </AutoPoint> </xsl:template> <xsl:template match="AutoPoint" mode="pass2"> <xsl:apply-templates select="*/*[1]" mode="pass2"/> </xsl:template> <xsl:template match="Name/*" mode="pass2"> <xsl:copy> <xsl:copy-of select="key('kDataPointBychildName', name())/*/*/*"/> </xsl:copy> </xsl:template>\[/code\]
 
Back
Top