I want to transform
<entry>
<parent1>
<object_id>1580</object_id>
</parent1>
<parent1>
<object_id>1586</object_id>
</parent1>
<parent2>
<object_id>1582</object_id>
</parent2>
<parent2>
<object_id>1592</object_id>
</parent2>
</entry>
into
<entry>
<parent1>1580-1586</parent1>
<parent2>1582-1592</parent2>
</entry>
Top-level entry name is unknown. Parent names are unknown, and the number of parent nodes with the same name can vary. Child nodes are known "object_id".
So, I would like to group the unknown parents in an abstract way, and concatenate child node values, delimited by "-".
Merge XML nodes using XSLT comes close to answering the question, as does Group/merge childs of same nodes in xml/xslt , but they're not quite what I need.
So far I have:
<xsl:key name="groupName" match="*[object_id]" use="."/>
<xsl:template match="*[generate-id(.) = generate-id(key('groupName', .))]">
<xsl:copy>
<xsl:call-template name="join">
<xsl:with-param name="list" select="object_id" />
<xsl:with-param name="separator" select="'-'" />
</xsl:call-template>
</xsl:copy>
</xsl:template>
<xsl:template name="join">
<xsl:param name="list" />
<xsl:param name="separator"/>
<xsl:for-each select="$list">
<xsl:value-of select="." />
<xsl:if test="position() != last()">
<xsl:value-of select="$separator" />
</xsl:if>
</xsl:for-each>
</xsl:template>
Thanks in advance!