简体   繁体   English

如何使用xslt部分转换xml?

[英]How to partially transform xml using xslt?

I am trying to do some XML data migration, migrating xml documents from one schema to another updated version. 我正在尝试进行一些XML数据迁移,将xml文档从一种模式迁移到另一种更新版本。 The changes are not huge so I am wondering whether there is a easy way for xslt to only transform partially the xml. 更改不会很大,所以我想知道xslt是否有一种简单的方法来仅部分转换xml。 eg rename an element name only etc. 例如,仅重命名元素名称,等等。

XSLT takes an input document and creates a new output document. XSLT接受输入文档并创建一个新的输出文档。 As for doing small changes, yes, start your stylesheet with the identity transformation template and add more specific templates for the changes eg 对于进行小的更改,是的,使用身份转换模板开始样式表,并为更改添加更多特定的模板,例如

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

<!-- identity transformation template -->
<xsl:template match="@* | node()">
  <xsl:copy>
    <xsl:apply-templates select="@* | node()"/>
  </xsl:copy>
</xsl:template>

<!-- rename foo to bar elements -->
<xsl:template match="foo">
  <bar>
    <xsl:apply-templates select="@* | node()"/>
  </bar>
</xsl:template>

</xsl:stylesheet>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM