Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我想重命名xml元素;产品「;至;项目「;不改变它的属性,但我不';我不知道怎么做_Xml_Xslt_Xml Parsing - Fatal编程技术网

我想重命名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" /> <

输入XML:

<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>