Jump to content

hagnik

Members
  • Posts

    1
  • Joined

  • Last visited

hagnik's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. 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>
×
×
  • Create New...