XML technologies / XSLT / XSLT Kochbuch / From XML to XML

(Excerpt from "XSLT Kochbuch" by Sal Mangano)

"Changing and improving are two different things."
German proverb

Introduction

One of the wonders of XML is that you can easily change an XML document if you do not like it. Since it is impossible to please everyone, XML-to-XML transformations are extremely common. Improving the structure of a poorly designed schema is not the only reason to transform XML, however. Sometimes you need to combine separate XML documents into a single document. At other times, you want to split a large document into several smaller ones. You may also want to prepare a document by filtering out the relevant information without changing its structure before passing it on for further processing.

A simple but important tool in many XML-to-XML transformations is the identity transformation. This is a stylesheet that transforms an input document into an output document without changing it. This task might seem better suited to the operating system’s copy function. As the following examples show, however, this simple stylesheet can be imported into other stylesheets to implement common transformations with very little additional code.

The following example shows this stylesheet. I prefer to call it the ‘copy stylesheet’ and refer to the techniques that use it as copying with overrides.

Example: copy.xslt

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="node() | @*">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>

  

  

 

 

 

back to top