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

Re: Indentation question

Subject: Re: Indentation question
From: iwantto keepanon <iwanttokeepanon@xxxxxxxx>
Date: Wed, 7 Sep 2005 03:20:55 +0400 (MSD)
proper indentation
"knocte " <knocte@xxxxxxxxx> writes: 
 
>>When you run a transformation and get breaks and spaces in the XML, 
>>that is no different than than your HTML analogy.  Whomever _consumes_ 
>>the XML needs to treat newlines as spaces.  Which keeps to your 
>>HTML/browser analogy. 
 
> Well, actually the thing is a web application that is consumed by a  
> browser, but I see that giving the response in only one line, like it  
> was "compressed", is shorter, cleaner and thus, better (I know that the  
> browser will ignore them too). 
 
You chose to add spaces and breaks to your HTML to make it more 
readable and the bandwidth apparently was not a concern then.  Since 
XML is also supposed to be readable, why insist on 1 line XML file? 

The sequences: 
   A: "this word" 
   B: "thatnword" 
 
are exactly the same length.  So A (1 line) is not more "compressed" 
than B (2 lines).  Sure you may save a few spaces it you delete 
indentation spaces, but that is probably nominal.  I dont necessarily 
buy "shorter, cleaner and thus, better". 
 
If I have an XML file that I need to view or edit, then I like to have 
proper indentation for readability.  If the XML is only going to be 
short lived and consumed by a computer, then I make sure it is at 
least well-formed (if not valid) and pretty much leave the spacing up 
to the tools ... they usually do the right thing(tm). 
 
> I think that I am wondering if a solution to this would be that the  
> second stylesheet that process the result of the first one should  
> normalize-space all tags that contain text unless the ones with an  
> attribute like notnormalize="false". What do you think? Is it possible? 
 
Sure it is.  In fact, there are a lot of ways to do this.  Here's one 
way off the top of my head (I'm sure the list can supply 100 others!): 
 
   <xsl:template match="text()[ not(parent::*/@notnormalize='false') ]"> 
      <xsl:value-of select="normalize-space(.)" /> 
   </xsl:template> 
 
Have fun, 
--  
Rodman

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.