Я пытаюсь создать новый элемент XML путем объединения нескольких элементов (некоторые с одинаковым именем) в новый элемент. Я могу создать новый элемент, присоединившись к элементам Publisher, но я не уверен, что делать дальше. Конечным результатом будет новый | элемент с разделителями, содержащий ключ, автора, название и издателя. Многозначные поля будут разделены запятыми. Я могу использовать XSL 1.0 или 2.0. Спасибо.
Входной файл
<Records>
<Record>
<Key>11111</Key>
<Author>AA</Author>
<Author>AB</Author>
<Author>AC</Author>
<Author>AD</Author>
<Author>AE</Author>
<Entrydate>10/12/1956</Entrydate>
<Title>Paper Title 1</Title>
<Title>Paper Title 2</Title>
<Title>Paper Title 3</Title>
<Title>Paper Title 4</Title>
<Title>Paper Title 5</Title>
<Publisher>Publisher 1</Publisher>
<Publisher>Publisher 2</Publisher>
<Publisher>Publisher 3</Publisher>
<Publisher>Publisher 4</Publisher>
<Publisher>Publisher 5</Publisher>
</Record>
<Record>
<Key>33333</Key>
<Author>BA</Author>
<Author>BB</Author>
<Entrydate>10/12/1965</Entrydate>
<Title>Paper Title 1</Title>
<Title>Paper Title 2</Title>
<Publisher>Publisher 1</Publisher>
<Publisher>Publisher 2</Publisher>
</Record>
<Record>
<Key>22222</Key>
<Author>CA</Author>
<Entrydate>11/12/1966</Entrydate>
<Title>Paper Title 1</Title>
<Publisher>Publisher 1</Publisher>
</Record>
<Record>
<Key>44444</Key>
<Author>DA</Author>
<Author>DB</Author>
<Author>DC</Author>
<Author>DD</Author>
<Author>DE</Author>
<Author>DF</Author>
<Entrydate>09/12/1976</Entrydate>
<Title>Paper Title 1</Title>
<Title>Paper Title 2</Title>
<Title>Paper Title 3</Title>
<Title>Paper Title 4</Title>
<Title>Paper Title 5</Title>
<Title>Paper Title 6</Title>
<Publisher>Publisher 1</Publisher>
<Publisher>Publisher 2</Publisher>
<Publisher>Publisher 3</Publisher>
<Publisher>Publisher 4</Publisher>
<Publisher>Publisher 5</Publisher>
<Publisher>Publisher 6</Publisher>
</Record>
</Records>
Желаемый вывод
<Records>
<Record>
<Key>11111</Key>
<Author>AA</Author>
<Author>AB</Author>
<Author>AC</Author>
<Author>AD</Author>
<Author>AE</Author>
<Entrydate>10/12/1956</Entrydate>
<Title>Paper Title 1</Title>
<Title>Paper Title 2</Title>
<Title>Paper Title 3</Title>
<Title>Paper Title 4</Title>
<Title>Paper Title 5</Title>
<Publisher>Publisher 1</Publisher>
<Publisher>Publisher 2</Publisher>
<Publisher>Publisher 3</Publisher>
<Publisher>Publisher 4</Publisher>
<Publisher>Publisher 5</Publisher>
<Combined>11111|AA, AB, AC, AD, AE|Paper Title 1, Paper Title 2, Paper Title 3, Paper Title 4, Paper Title 5|Publisher 1, Publisher 2, Publisher 3, Publisher 4, Publisher 5</Combined>
</Record>
<Record>
<Key>33333</Key>
<Author>BA</Author>
<Author>BB</Author>
<Entrydate>10/12/1965</Entrydate>
<Title>Paper Title 1</Title>
<Title>Paper Title 2</Title>
<Publisher>Publisher 1</Publisher>
<Publisher>Publisher 2</Publisher>
<Combined>33333|BA, BB|Paper Title 1, Paper Title 2|Publisher 1, Publisher 2</Combined>
</Record>
<Record>
<Key>22222</Key>
<Author>CA</Author>
<Entrydate>11/12/1966</Entrydate>
<Title>Paper Title 1</Title>
<Publisher>Publisher 1</Publisher>
<Combined>22222|CA|Paper Title 1|Publisher 1</Combined>
</Record>
<Record>
<Key>44444</Key>
<Author>DA</Author>
<Author>DB</Author>
<Author>DC</Author>
<Author>DD</Author>
<Author>DE</Author>
<Author>DF</Author>
<Entrydate>09/12/1976</Entrydate>
<Title>Paper Title 1</Title>
<Title>Paper Title 2</Title>
<Title>Paper Title 3</Title>
<Title>Paper Title 4</Title>
<Title>Paper Title 5</Title>
<Title>Paper Title 6</Title>
<Publisher>Publisher 1</Publisher>
<Publisher>Publisher 2</Publisher>
<Publisher>Publisher 3</Publisher>
<Publisher>Publisher 4</Publisher>
<Publisher>Publisher 5</Publisher>
<Publisher>Publisher 6</Publisher>
<Combined>44444|DA, DB, DC, DD, DE, DF|Paper Title 1, Paper Title 2, Paper Title 3, Paper Title 4, Paper Title 5, Paper Title 6|Publisher 1, Publisher 2, Publisher 3, Publisher 4, Publisher 5, Publisher 6</Combined>
</Record>
</Records>
Код пока
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="no" indent="yes" />
<xsl:strip-space elements="*" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Record">
<xsl:copy>
<xsl:copy-of select="Publisher"/>
<xsl:apply-templates select="*[not(self::Publisher)]" />
<Combined>
<xsl:apply-templates select="Publisher/text()" />
</Combined>
</xsl:copy>
</xsl:template>
<xsl:template match="Publisher/text()">
<xsl:if test="position() > 1">|</xsl:if>
<xsl:value-of select="."/>
</xsl:template>
</xsl:stylesheet>