Jump to content

merging multiple records


hagnik
 Share

Recommended Posts

I have been struggling with this for days. I have some elements with multiple attributes which causes multiple records. I need to merge these. See my sample xml, my expected output, and what my xsl is so far. Any help would be much appreciated. Sample xml:<ExportXML xmlns="http://www.taleo.com/ws/integration/toolkit/2005/07"> <record> <field name="action">update</field> <field name="clientjobid">1100744</field> <field name="customfield1">Sales</field> </record> <record> <field name="action">update</field> <field name="clientjobid">1100744</field> <field name="customfield1">SmartGrid</field> </record> <record> <field name="action">update</field> <field name="clientjobid">1100744</field> <field name="customfield1">West-USA</field> </record> <record> <field name="action">update</field> <field name="clientjobid">1200323</field> <field name="customfield1">Consulting</field> </record></ExportXML> What I need: <job> <action>update</action> <clientjobid>1100744</clientjobid> <customfield1>Sales, SmartGrid, West-USA</customfield1> </job> <job> <action>update</action> <clientjobid>1200323</clientjobid> <customfield1>Consulting</ customfield1> </job> Current xsl: (that is not working properly)<xsl:stylesheet version="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"xmlns:t="http://www.taleo.com/ws/integration/toolkit/2005/07"exclude-result-prefixes="t"> <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/> <xsl:key name="distinctRecord" match="t:record" use="t:field[@name=clientjobid]" /> <xsl:template match="/"> <jobs> <xsl:for-each select="//t:record[generate-id(.) = generate-id(key('distinctRecord',./t:field[@name=clientjobid])[1])]"> <xsl:variable name="clientjobid" select="t:field[@name=clientjobid]" /> <job> <action><xsl:value-of select="t:field[@name=action]" /></action> <clientjobid><xsl:value-of select="$clientjobid" /></clientjobid> <customfield1> <xsl:for-each select="//t:field[@name='clientjobid' and .=$clientjobid]/.."> <xsl:if test="position() != 1">, </xsl:if> <xsl:value-of select="t:field[@name=customfield1][1]" /> </xsl:for-each> </customfield1> </job> </xsl:for-each> </jobs> </xsl:template></xsl:stylesheet>

Link to comment
Share on other sites

Here is an adapted stylesheet

<xsl:stylesheet version="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"xmlns:t="http://www.taleo.com/ws/integration/toolkit/2005/07"exclude-result-prefixes="t"><xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/><xsl:key name="distinctRecord" match="t:record" use="t:field[@name='clientjobid']" /><xsl:template match="/"><jobs>  <xsl:for-each select="//t:record[generate-id(.) = generate-id(key('distinctRecord', t:field[@name='clientjobid'])[1])]">    <xsl:variable name="clientjobid" select="t:field[@name='clientjobid']" />    <job>	  <action><xsl:value-of select="t:field[@name='action']" /></action>	  <clientjobid><xsl:value-of select="$clientjobid" /></clientjobid>	  <customfield1>	    <xsl:for-each select="key('distinctRecord', $clientjobid)">		  <xsl:if test="position() != 1">, </xsl:if>		  <xsl:value-of select="t:field[@name='customfield1']"/>		 </xsl:for-each>	  </customfield1>    </job>  </xsl:for-each></jobs></xsl:template></xsl:stylesheet>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...