我有一个这样的 XML 结构:
<GetAccount_Output>
<GetAccountResponse>
<AccountCollection>
<Account>
<AccountId>1</AccountId>
</Account>
</AccountCollection>
</GetAccountResponse>
<GetAccountResponse>
<AccountCollection>
<Account>
<AccountId>2</AccountId>
</Account>
</AccountCollection>
</GetAccountResponse>
</GetAccount_Output>
所需的输出是:
<GetAccount_Output>
<GetAccountResponse>
<AccountCollection>
<Account>
<AccountId>1</AccountId>
</Account>
<Account>
<AccountId>2</AccountId>
</Account>
</AccountCollection>
</GetAccountResponse>
</GetAccount_Output>
我可以设法删除一个:
<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>
给出这个结果:
<GetAccount_Output>
<AccountCollection>
<Account>
<AccountId>1</AccountId>
</Account>
<Account>
<AccountId>2</AccountId>
</Account>
</AccountCollection>
</GetAccount_Output>
但我不知道如何合并GetAccountResponse
和AccountCollection
?谁能将我推向正确的解决方案?