[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: How to get comments to indent on their own line in

Subject: Re: How to get comments to indent on their own line in XML output?
From: David Carlisle <davidc@xxxxxxxxx>
Date: Sun, 6 Jul 2008 22:06:37 +0100
Re:  How to get comments to indent on their own line in
>  <xsl:text>&#10;&#xA0;&#09;</xsl:text>

That's a very unsafe way of indenting it will almost always make the
resulting document invalid.

A0 is no breaking space which may look white but is not "whitespace" as
defined by XML so if you indent element content using that the resuklt
will have PCDATA where none is allowed. Just use
<xsl:text>&#10;  </xsl:text>
to indent by a newline and two spaces (or however many spaces you need)

> I guess that I'm really expecting the simple case to work, where
> indentation comes out as a function of nested children without having 
> to add extraneous text nodes.

Your intutition is leading you to exect comments to act as elements
during indentation but as Michael explained that isn't really a safe
assumption, comments can appear in text only element content, and so
the system is treating them (more or less) like text nodes as far as
indentation is concerned. If you don't like that, possibly the simplest
thing to do is instead of using xsl:comment use 
<myCommentElement>this is a comment<myCommentElement>
then it will indent as you wish. then to get it back to being a comment
either do a second transform with an identity transform plust one
template to switch this back or just use
sed -i -e "s/<myCommentElement>/<!--" -e "s/</myCommentElement>/-->" file.xml
(or perl or any other language of choice).

David

PS sorry, in my reply to MDP I accused you of having been the source of 
a surious <xs:text in an attribute value, it appears it was me, must have
accidentally yanked it one line two early:-)



________________________________________________________________________
The Numerical Algorithms Group Ltd is a company registered in England
and Wales with company number 1249803. The registered office is:
Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.

This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs. 
________________________________________________________________________

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.