0

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. e.g. rename an element name only etc.

1
  • Essentially, this is answered here. Commented Nov 25, 2015 at 13:34

1 Answer 1

1

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 e.g.

<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>
Sign up to request clarification or add additional context in comments.

1 Comment

If you're using XSLT 2.0 and got lots of rules that involve renaming a single element (and no other changes), you can go one step further and define your mapping in a global variable and write a template that handles all of them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.