XSL Pass Transformation- standard Muenchian grouping

Uncle_Unix

New Member
I was trying to make number of pass transformations on an XML using XSLT to another xml. But unable to Achieve. Help is appreciated with the code.I have worked out with the solution that was provided if no elements were matching and muenchian grouping by @DimitreNovatchev. In this case the "" Car_MNO, Car_Model "" are being matched and then the other values are being subgrouped. \[code\]Input XML:<t><Vehicle><Car_MNo>123</Car_MNo><Car_Model>Audi</Car_Model><Description>car.color</Description><colour>BLACK</colour></Vehicle><Vehicle><Car_MNo>123</Car_MNo><Car_Model>Audi</Car_Model><Description>car.hood</Description><colour>RED</colour></Vehicle><Vehicle><Car_MNo>123</Car_MNo><Car_Model>BMW</Car_Model><Description>Bus.Brakes</Description><colour>steel</colour></Vehicle><Vehicle><Car_MNo>123</Car_MNo><Car_Model>BMW</Car_Model><Description>Bus.steering</Description><colour>black</colour></Vehicle><Vehicle><Car_MNo>234</Car_MNo><Car_Model>benz</Car_Model><Description>cycle.color</Description><colour>violet</colour></Vehicle><Vehicle><Car_MNo>345</Car_MNo><Car_Model>nissan</Car_Model><Description>bike.seat</Description><colour>RED</colour></Vehicle><Vehicle><Car_MNo>345</Car_MNo><Car_Model>nissan</Car_Model><Description>car</Description><colour>RED</colour></Vehicle></t>\[/code\]Expected Output in XML:\[code\] <t> <Vehicle> <car> <color>BLACK</color> <hood>RED</hood> </car> <Bus> <Brakes>steel</Brakes> <Steering>black</Steering> </Bus> <cycle> <color>violet</color> </cycle> <bike> <seat>Red</seat> </bike> </Vehicle> <vehicle> <car>red</car> </vehicle></t>\[/code\]Sample Code I worked looks like this:\[code\]<Vehicle> <xsl:variable name="vrtfPass2"><xsl:apply-templates/> </xsl:variable> <xsl:apply-templates mode="pass3" select="ext:node-set($vrtfPass2)/* [generate-id()=generate- id(key('kvehiclechild', name(Name/*[1]))[1])] "/> <xsl:for-each select="//Vehicle"> <xsl:if test="not(contains(Description,'.'))"> <xsl:variable name="var3" select="Description"/> <xsl:element name="{$var3}"> <xsl:value-of select="colour"/> </xsl:element> </xsl:if> </xsl:for-each> </Vehicle> <Vehicle> <xsl:variable name="vrtfPass3"> <xsl:apply-templates/> </xsl:variable> <xsl:apply-templates mode="pass4" select="ext:node-set($vrtfPass3)/* [generate-id()= generate- id(key('kvehicle_au', name(Description/*[1]))[1])] "/> </Vehicle> <xsl:template match="Vehicle"> <Vehicle> <car><xsl:if test="contains(Description,'.')"> <xsl:element name="{concat(substring-before(Description, '.'),substring-after (Profile, ' '))}"><xsl:element name="{substring-after(Description, '.')}"><xsl:value-of select="Value"/></xsl:element></xsl:element></xsl:if> </car> </Vehicle> </xsl:template> <xsl:template match="Vehicle" mode="pass3"> <xsl:apply-templates select="*/*[1]" mode="pass3"/> </xsl:template>\[/code\]
 
Back
Top