我想重命名xml元素;产品「;至;项目「;不改变它的属性,但我不';我不知道怎么做
输入XML:我想重命名xml元素;产品「;至;项目「;不改变它的属性,但我不';我不知道怎么做,xml,xslt,xml-parsing,Xml,Xslt,Xml Parsing,输入XML: <ProductList> <Product Action="Manage" ProductID="Item_1"> <PrimaryInformation Description="Item 1" Status="3000" ShortDescription="Item 1" /> <
<ProductList>
<Product Action="Manage" ProductID="Item_1">
<PrimaryInformation Description="Item 1"
Status="3000" ShortDescription="Item 1" />
</Product>
<Product Action="Manage" ProductID="Item_2">
<PrimaryInformation Description="Item 2"
Status="3000" ShortDescription="Item 2" />
</Product>
<Product Action="Manage" ProductID="Item_3">
<PrimaryInformation Description="Item 3"
Status="3000" ShortDescription="Item 3" />
</Product>
</ProductList>
预期的XML输出:
<ProductList >
<Item Action="Manage" ProductID="Item_1" >
<PrimaryInformation Description="Item 1" Status="3000" ShortDescription="Item 1" />
</Item>
<Item Action="Manage" ProductID="Item_2" >
<PrimaryInformation Description="Item 2" Status="3000" ShortDescription="Item 2" />
</Item>
<Item Action="Manage" ProductID="Item_3" >
<PrimaryInformation Description="Item 3" Status="3000" ShortDescription="Item 3" />
</Item>
</ProductList>
我尝试了这个XML模板,它正在工作,但它也删除了该元素中存在的所有属性
<xsl:template match="Product">
<xsl:element name="Item">
<xsl:apply-templates />
</xsl:element>
</xsl:template>
请尝试以下XSLT 它遵循身份转换模式 XSLT
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="utf-8" indent="yes" omit-xml-declaration="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Product">
<Item >
<xsl:apply-templates select="@*|node()"/>
</Item >
</xsl:template>
</xsl:stylesheet>