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 XSL是否替换标记/元素并重新保存文件?_Xml_Xslt - Fatal编程技术网

Xml XSL是否替换标记/元素并重新保存文件?

Xml XSL是否替换标记/元素并重新保存文件?,xml,xslt,Xml,Xslt,我在XSL函数方面没有很多经验 我有各种各样的现有文件,并且会有一堆不断的新文件,这些文件是各种“风格”的XML。NITF等 我想做的是处理所有XML文件,用新元素名替换某些元素,然后重新保存它们 使用氧气作为应用程序。这些文件最终将被DAM接收 i、 e.在XML文件中,包含以下代码: <abstract> <hl2>Mercy for Animals doesn’t work on tips. Its investigators go where they g

我在XSL函数方面没有很多经验

我有各种各样的现有文件,并且会有一堆不断的新文件,这些文件是各种“风格”的XML。NITF等

我想做的是处理所有XML文件,用新元素名替换某些元素,然后重新保存它们

使用氧气作为应用程序。这些文件最终将被DAM接收

i、 e.在XML文件中,包含以下代码:

<abstract>
    <hl2>Mercy for Animals doesn’t work on tips. Its investigators go where they get hired, with cameras.</hl2>
</abstract>

怜悯动物不需要小费。它的调查人员带着摄像机去他们被雇佣的地方。
我想做以下代码:

<title>
    <hl2>Mercy for Animals doesn’t work on tips. Its investigators go where they get hired, with cameras.</hl2>
</title>

怜悯动物不需要小费。它的调查人员带着摄像机去他们被雇佣的地方。
因此,只需简单地搜索和替换XML文件,然后重新保存它们,保存文件名等,并保留结构等

代码可以添加不同的转换吗


基本上,原因是从各种来源摄取各种XML文件,转换成DAM所需的XML格式。可能是XSL-FO?

当XSLT问题相当于“保持大部分内容不变,但调整X、Y和Z”时,标准答案是使用“标识转换”。这是一个单一的模板,它会将输入文档复制到输出,但不会改变,但可以被其他更具体的模板选择性地覆盖以进行修改。最基本的意思是

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

  <!-- identity template - copy everything verbatim except for ... -->
  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()" />
    </xsl:copy>
  </xsl:template>

  <!-- ... abstract elements, which we rename to title -->
  <xsl:template match="abstract">
    <title>
      <xsl:apply-templates select="@*|node()" />
    </title>
  </xsl:template>
</xsl:stylesheet>

因为在匹配模式和XPath表达式中不固定的名称总是意味着没有命名空间的节点。

谢谢。我想我遗漏的可能是名称空间/匹配表达式。
<xsl:stylesheet ....
      xmlns:ex="http://example.com">

  <xsl:template match="ex:abstract">