我有一个用于绑定的 xml 文件:
<?xml version="1.0" encoding="utf-16"?>
<MyCustomer>
<Customers>
<CutomerCode>C001</CutomerCode>
<CustomerName>Shahbaz</CustomerName>
<City>Karachi</City>
<Country>Pakistan</Country>
</Customers>
<Customers>
<CutomerCode>C002</CutomerCode>
<CustomerName>Imran</CustomerName>
<City>Lahore</City>
<Country>Pakistan</Country>
</Customers>
</MyCustomer>
我正在应用 XSLT:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:strip-space elements="*"/>
<xsl:output indent="yes"/>
<xsl:template match="MyCustomer">
<xsl:copy>
<Customers>
<xsl:apply-templates select="Customers/*"/>
</Customers>
</xsl:copy>
</xsl:template>
<xsl:template match="Customers/*">
<xsl:copy>
<xsl:value-of select="."/>
</xsl:copy>
</xsl:template>
<xsl:template match="Customers/City">
<xsl:element name="Address">
<xsl:element name="City">
<xsl:value-of select="." />
</xsl:element>
</xsl:element>
</xsl:template>
<xsl:template match="Customers/Country">
<xsl:element name="Address">
<xsl:element name="Country">
<xsl:value-of select="." />
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
这个 XSLT 给了我结果:
<?xml version="1.0" encoding="utf-16"?>
<MyCustomer>
<Customers>
<CutomerCode>C001</CutomerCode>
<CustomerName>Shahbaz</CustomerName>
<Address>
<City>Karachi</City>
</Address>
<Address>
<Couontry>Pakistan</Couontry>
</Address>
<CutomerCode>C002</CutomerCode>
<CustomerName>Imran</CustomerName>
<Address>
<City>Lahore</City>
</Address>
<Address>
<Country>Pakistan</Country>
</Address>
</Customers>
</MyCustomer>
虽然我需要这样的转换:
<?xml version="1.0" encoding="utf-16"?>
<MyCustomer>
<Customers>
<CutomerCode>C001</CutomerCode>
<CustomerName>Shahbaz</CustomerName>
<Address>
<City>Karachi</City>
<Country>Pakistan</Country>
</Address>
<CutomerCode>C002</CutomerCode>
<CustomerName>Imran</CustomerName>
<Address>
<City>Lahore</City>
<Couontry>Pakistan</Couontry>
</Address>
</Customers>
</MyCustomer>
请帮助我想要正确的转换。请帮助我想要正确的 xslt 方法请帮助