Re: [xsl] Preserve the structure in output

Subject: Re: [xsl] Preserve the structure in output
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Wed, 18 Jul 2001 17:43:57 +0100
Hi Earl,

> I have a doubt like when i do a transformation of one xml file into
> another xml file my resuling xml file does not maintan the structure
> of the previous file like

Probably you don't really care about the *precise* whitespace in the
result, but just want it to be indented so that you can read it
better. If so, you can tell the processor to indent your output with:

<xsl:output indent="yes" />

However, if you do care that the whitespace in the result is the same
as the whitespace in the source, then you have to add the values of
the whitespace-only text nodes in the source to the result. This
usually happens by default. There are several reasons that it might
not be:

First, the whitespace might be present in the source node tree, but
you might not be outputting it. Perhaps you're not applying templates
to it? Or perhaps you're applying templates but have a template that
doesn't copy whitespace when it's encountered.

Second, you might be stripping the whitespace from the source tree
with a xsl:strip-space element at the top level of your stylesheet. If
you have one of these, remove it, or override it for all B elements
(inside which you want whitespace to be preserved) with:

<xsl:preserve-space elements="B" />

or override it for a particular B element using the xml:space
attribute set to 'preserve':

<B xml:space="preserve">
  <C>this is c</C>

Third, you might be using MSXML, which strips all whitespace unless
you tell it not to. To preserve whitespace in that case, you need to
script the transformation and tell MSXML not to strip the whitespace

  DOMDocument.preserveWhiteSpace = true;

or again you can use the xml:space attribute set to 'preserve' in
the source to indicate that whitespace should be preserved in a
particular section of your XML document.

I hope that helps,


Jeni Tennison

 XSL-List info and archive:

Current Thread