This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Preserve the structure in output
- To: "Earl Spencer" <eapencer74 at hotmail dot com>
- Subject: Re: [xsl] Preserve the structure in output
- From: Jeni Tennison <mail at jenitennison dot com>
- Date: Wed, 18 Jul 2001 17:43:57 +0100
- CC: XSL-List at lists dot mulberrytech dot com
- Organization: Jeni Tennison Consulting Ltd
- References: <F187i6nx8dyDd3OJXsN00000759@hotmail.com>
- Reply-To: xsl-list at lists dot mulberrytech dot com
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>
</B>
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
with:
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
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list