简体   繁体   中英

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. The changes are not huge so I am wondering whether there is a easy way for xslt to only transform partially the xml. eg rename an element name only etc.

XSLT takes an input document and creates a new output document. 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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