Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.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 XSLT简单转换_Xml_Xslt - Fatal编程技术网

Xml XSLT简单转换

Xml XSLT简单转换,xml,xslt,Xml,Xslt,我有一个非常简单的任务,但我被困在这里 因此,我有如下XML文件: <entries> <entry> <field>field value</field> </entry> ... <entry> <field>field value</field> </entry> <entries> <entry field="field value"> .

我有一个非常简单的任务,但我被困在这里

因此,我有如下XML文件:

<entries>
<entry>
    <field>field value</field>
</entry>
...
<entry>
    <field>field value</field>
</entry>
<entries>
<entry field="field value">
...
<entry field="field value">
</entries>

字段值
...
字段值

它应该用XSLT进行转换,如下所示:

<entries>
<entry>
    <field>field value</field>
</entry>
...
<entry>
    <field>field value</field>
</entry>
<entries>
<entry field="field value">
...
<entry field="field value">
</entries>

...

你能帮我做一下模板吗?提前非常感谢。

这可以通过以下XSLT完成:

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    version="1.0">
<xsl:output method="xml" omit-xml-declaration="yes" encoding="UTF-8" 
    indent="yes" />
<xsl:strip-space elements="*"/>
  <xsl:template match="/">
    <xsl:apply-templates/>
  </xsl:template>
  <xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>
  <xsl:template match="entry">
    <xsl:copy>
        <xsl:attribute name="field">
          <xsl:value-of select="field"/>
        </xsl:attribute> 
      <xsl:apply-templates/>
    </xsl:copy>
  </xsl:template>
  <xsl:template match="field"/>
</xsl:transform>
模板匹配的
字段
为空,并删除
字段
节点

<xsl:copy>
  <xsl:attribute name="field">
    <xsl:value-of select="field"/>
  </xsl:attribute> 
  <xsl:apply-templates/>
</xsl:copy>