Skip to Content
XSLT Cookbook, 2nd Edition
book

XSLT Cookbook, 2nd Edition

by Sal Mangano
December 2005
Intermediate to advanced content levelIntermediate to advanced
774 pages
19h 30m
English
O'Reilly Media, Inc.
Content preview from XSLT Cookbook, 2nd Edition

Chapter 8. XML to XML

To change and to change for the better are two different things.

German proverb

Introduction

One of the beauties of XML is that if you don’t like some XML document, you can change it. Since it is impossible to please everyone, transforming XML to XML is extremely common. However, you will not transform XML only to improve the structure of a poorly designed schema. Sometimes you need to merge disparate XML documents into a single document. At other times, you want to break up a large document into smaller subdocuments. You might also wish to preprocess a document to filter out only the relevant information, without changing its structure, before sending it off for further processing.

A simple but important tool in many XML-to-XML transformations is the identity transform. This tool is a stylesheet that copies an input document to an output document without changing it. This task may seem better suited to the operating systems copy operation, but as the following examples demonstrate, this simple stylesheet can be imported into other stylesheets to yield very common types of transformations with little added coding effort.

Example 8-1 shows the identity stylesheet. I actually prefer calling this stylesheet the copying stylesheet, and I call the techniques that utilize it the overriding copy idiom .

Example 8-1. copy.xslt (continued)
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="node() | @*"> <xsl:copy> <xsl:apply-templates ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

XSLT Cookbook

XSLT Cookbook

Sal Mangano
XSLT, 2nd Edition

XSLT, 2nd Edition

Doug Tidwell
XSLT for Dummies

XSLT for Dummies

Richard Wagner
XSLT

XSLT

Doug Tidwell

Publisher Resources

ISBN: 0596009747Supplemental ContentErrata Page