This is actually a follow-up question to my previous one but I've iterated my problem so maybe this is easier to solve. I have XML data in following format:
<v1:publications xmlns:commons="v3.commons.pure.atira.dk"
xmlns:v1="v1.publication-import.base-uk.pure.atira.dk">
<v1:book id="1" subType="book">
<v1:peerReviewed>true</v1:peerReviewed>
<v1:publicationCategory>scientific</v1:publicationCategory>
<v1:publicationStatus>published</v1:publicationStatus>
<v1:language>fi</v1:language>
<v1:title>
<commons:text>Introduction to scientific reduction</commons:text>
</v1:title>
<v1:abstract/>
<v1:persons>
<v1:author>
<v1:role>author</v1:role>
<v1:person>
<v1:firstName>Jane</v1:firstName>
<v1:lastName>Smith</v1:lastName>
</v1:person>
</v1:author>
</v1:persons>
<v1:organisations>
<v1:organisation id="2250500"/>
</v1:organisations>
<v1:owner id="2250500"/>
<v1:publicationDate>
<commons:year>2013</commons:year>
</v1:publicationDate>
<v1:visibility>Public</v1:visibility>
<v1:numberOfPages>2</v1:numberOfPages>
</v1:book>
<v1:book id="1" subType="book">
<v1:persons>
<v1:author>
<v1:role>author</v1:role>
<v1:person>
<v1:firstName>John</v1:firstName>
<v1:lastName>Doe</v1:lastName>
</v1:person>
</v1:author>
</v1:persons>
<v1:organisations>
<v1:organisation id="220300"/>
</v1:organisations>
</v1:book>
</publications>
The XSLT I've so far is this:
<?xml version="1.0"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:commons="v3.commons.pure.atira.dk"
xmlns:v1="v1.publication-import.base-uk.pure.atira.dk"
exclude-result-prefixes="xsi xs"
version="2.0">
<xsl:output method="xml" indent="yes" />
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<v1:publications>
<xsl:for-each-group select="/v1:publications/v1:book" group-by="@id">
<xsl:for-each-group select="current-group()" group-by="if(@Key) then @Key else 'no key'">
<v1:book>
<!-- Copy attributes off the *first* GroupData element in the group -->
<xsl:copy-of select="current-group()[1]/@*"/>
<!-- Copy ItemData children from *all* GroupData elements in the group -->
<xsl:copy-of select="current-group()/*" />
</v1:book>
</xsl:for-each-group>
</xsl:for-each-group>
</v1:publications>
Problem is that it creates separate nodes under <v1:book>
for duplicates (v1:persons) when I would like to combine them like this:
<v1:persons>
<v1:author></v1:author>
<v1:author></v1:author>
</v1:persons>
Fields like <v1:title/>
I could easily remove from the XML beforehand so they are not a problem.
Desired output should be like the following, I edited few fields (organisation id and owner id to correct ones). This is actual data that imports correctly.
<?xml version="1.0" encoding="UTF-8"?>
<v1:publications xmlns:commons="v3.commons.pure.atira.dk"
xmlns:v1="v1.publication-import.base-uk.pure.atira.dk">
<v1:book id="1" subType="book">
<v1:peerReviewed>true</v1:peerReviewed>
<v1:publicationCategory>scientific</v1:publicationCategory>
<v1:publicationStatus>published</v1:publicationStatus>
<v1:language>fi_FI</v1:language>
<v1:title>
<commons:text>Introduction to scientific reduction</commons:text>
</v1:title>
<v1:persons>
<v1:author>
<v1:role>author</v1:role>
<v1:person>
<v1:firstName>Jane</v1:firstName>
<v1:lastName>Smith</v1:lastName>
</v1:person>
</v1:author>
<v1:author>
<v1:role>author</v1:role>
<v1:person>
<v1:firstName>John</v1:firstName>
<v1:lastName>Die</v1:lastName>
</v1:person>
</v1:author>
</v1:persons>
<v1:organisations>
<v1:organisation id="2250500"/>
<v1:organisation id="2250300"/>
</v1:organisations>
<v1:owner id="2250300"/>
<v1:publicationDate>
<commons:year>2013</commons:year>
</v1:publicationDate>
<v1:visibility>Public</v1:visibility>
<v1:numberOfPages>2</v1:numberOfPages>
</v1:book>
</v1:publications>