XSLT for Dummies
|
Chapter 13 - Gimme Some Space and Other Output Issues | |
XSLT For Dummies | |
by Richard Wagner | |
Hungry Minds 2002 |
The xsl:output element includes the indent attribute, which enables you to specify whether the XSLT processor can indent the result document so that the document displays the hierarchy of the tree. Indenting your result document can help others read it but doesnt impact how the document is processed . For example, imagine you have a flat-looking XML file that you want to transform into something more readable. Start with the following source: <topfilms createdby="AFI"> <film place="1" date="1941">Citizen Kane</film> <film place="2" date="1942">Casablanca</film> <film place="3" date="1972">The Godfather</film> <film place="4" date="1939">Gone With The Wind</film> <film place="5" date="1962">Lawrence Of Arabia</film> <film place="6" date="1939">The Wizard Of Oz</film> <film place="7" date="1967">The Graduate</film> <film place="8" date="1954">On The Waterfront</film> <film place="9" date="1993">Schindler's List</film> <film place="10" date="1952">Singin' In The Rain</film> </topfilms> You can use the following stylesheet to copy all the elements into an indented output: <xsl:output method="xml" indent="yes"/> <xsl:template match="/"> <xsl:copy-of select="*"/> </xsl:template> When the stylesheet is applied to the XML source, the XSLT processor indents each level of the result tree hierarchy, resulting in a much more legible document: <topfilms createdby="AFI"> <film place="1" date="1941">Citizen Kane</film> <film place="2" date="1942">Casablanca</film> <film place="3" date="1972">The Godfather</film> <film place="4" date="1939">Gone With The Wind</film> <film place="5" date="1962">Lawrence Of Arabia</film> <film place="6" date="1939">The Wizard Of Oz</film> <film place="7" date="1967">The Graduate</film> <film place="8" date="1954">On The Waterfront</film> <film place="9" date="1993">Schindler's List</film> <film place="10" date="1952">Singin' In The Rain</film> </topfilms> Warning By using the indent="yes" option, you tell the XSLT processor that it can indent to show the document hierarchy. But, that does not necessarily mean that all processors support indenting. Some processors, like Saxon, provide explicit support for indenting, while others ( msxsl ) do not.
|