I have an XML structure as such:
<GetAccount_Output>
<GetAccountResponse>
<AccountCollection>
<Account>
<AccountId>1</AccountId>
</Account>
</AccountCollection>
</GetAccountResponse>
<GetAccountResponse>
<AccountCollection>
<Account>
<AccountId>2</AccountId>
</Account>
</AccountCollection>
</GetAccountResponse>
</GetAccount_Output>
The desired output is:
<GetAccount_Output>
<GetAccountResponse>
<AccountCollection>
<Account>
<AccountId>1</AccountId>
</Account>
<Account>
<AccountId>2</AccountId>
</Account>
</AccountCollection>
</GetAccountResponse>
</GetAccount_Output>
I can manage to remove one:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/*">
<xsl:copy>
<GetAccountResponse>
<xsl:copy-of select="GetAccountResponse/*"/>
</GetAccountResponse>
<xsl:apply-templates select="*[name()!='GetAccountResponse']"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Giving this result:
<GetAccount_Output>
<AccountCollection>
<Account>
<AccountId>1</AccountId>
</Account>
<Account>
<AccountId>2</AccountId>
</Account>
</AccountCollection>
</GetAccount_Output>
But I don't know how I can merge both GetAccountResponse
and AccountCollection
?
Anyone who can push me towards the correct solution?