0
我有这样的XML:XSL收集多个错误节点为一个节点
<Envelope>
<Body>
<Response>
<return>
<contact_main>
<firstname>John</firstname>
<lastname>Doe</lastname>
<error>false</error>
<errors/>
</contact_main>
<contact_info1>
<address1>High Road 748</address1>
<zip>N17 0AP</zip>
<city>London</city>
<country_name>England</country_name>
<error>true</error>
<errors>
<item>
<text>Some error text here</text>
</item>
</errors>
</contact_info1>
<contact_card>
<number>12345678</number>
<status>Expired</status>
<valid_to>2010-01-02Z</valid_to>
<valid>false</valid>
<error>true</error>
<errors>
<item>
<text>Card is not valid.</text>
</item>
</errors>
</contact_card>
</return>
</Response>
<account_name>No name</account_name>
<number>12345678</number>
</Body>
</Envelope>
有了这个XSL:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:output method="xml" encoding="utf-8" indent="yes"/>
<xsl:template match="Response">
<response>
<contact>
<xsl:copy-of select="return/contact_main/node()"/>
<xsl:copy-of select="return/contact_info1/node()"/>
</contact>
<card>
<xsl:copy-of select="return/contact_card/node()"/>
</card>
</response>
</xsl:template>
<xsl:template match="account_name"/>
<xsl:template match="number"/>
</xsl:stylesheet>
我得到以下结果:
<response>
<contact>
<firstname>John</firstname>
<lastname>Doe</lastname>
<error>false</error>
<errors />
<address1>High Road 748</address1>
<zip>N17 0AP</zip>
<city>London</city>
<country_name>England</country_name>
<error>true</error>
<errors>
<item>
<text>Some error text here</text>
</item>
</errors>
</contact>
<card>
<number>12345678</number>
<status>Expired</status>
<valid_to>2010-01-02Z</valid_to>
<valid>false</valid>
<error>true</error>
<errors>
<item>
<text>Card is not valid.</text>
</item>
</errors>
</card>
</response>
在结果,有多个节点具有相同的名称“错误”和“错误”。 我想从他们的父母身上取出它们并将它们全部添加到xml的底部,所以我将有1个“错误”节点和1个“错误”数组,其中包含来自整个xml的所有错误文本。
所以最终的XML将是这样的:
<response>
<contact>
<firstname>John</firstname>
<lastname>Doe</lastname>
<address1>High Road 748</address1>
<zip>N17 0AP</zip>
<city>London</city>
<country_name>England</country_name>
</contact>
<card>
<number>12345678</number>
<status>Expired</status>
<valid_to>2010-01-02Z</valid_to>
<valid>false</valid>
</card>
<error>true</error>
<errors>
<text>Some error text here</text>
<text>Card is not valid.</text>
</errors>
</response>
这可能吗?
应该用''节点发生什么,如果它有不同的价值观沿源XML? –
DRCB
如果源xml中的任何节点都为真,则节点值应该为true。 –
bale3