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

Re: saxon xmlspy discrepancy in whitespace handling

Subject: Re: saxon xmlspy discrepancy in whitespace handling
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Wed, 17 Jan 2007 14:45:24 +0100
Re:  saxon xmlspy discrepancy in whitespace handling
David Carlisle wrote:
<xsl:variable name="newline" select=" '&#10;' " />

2nd one, not the 1st (which is equivalent to <xsl:variable
name="newline"/>

Oops!


(side note:)
I tend to solve my own whitespace problems with character maps, so that I can use a private use character everywhere in my code. That way I do not need to think about the whitespace removal of the stylesheet:


inside a stylesheet dtd:

<!ENTITY newline "&#38;#x0A;" >
<!ENTITY newline_substitute "&#xE0F2;" >   <!-- mapped to newline -->
<!ENTITY nsub "&newline_substitute;" >     <!-- alias -->

the xslt:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet SYSTEM "../../xslt-common/dtd/webitor-transformation.dtd" >


<xsl:stylesheet
   version                    = "2.0"
   xmlns:xsl                = "http://www.w3.org/1999/XSL/Transform" >

<xsl:character-map name="substitutes">
<xsl:output-character character="&newline_substitute;" string="&newline;"/>
</xsl:character-map>


<xsl:output use-character-map="substitutes" />

   <xsl:template match="/">
       <xsl:value-of select=" '&nsub;' " />
   </xsl:template>
</xsl:stylesheet>


In the example above there is no reason at all of course for using &nbsub; instead of &#10; unless for readability (but you could use &newline; too). However, when passing around variables, doing copy-of, value-of etc, or even a normalice-space, you can loose the newlines. This way you can preserve them more easily and, the better part, when I place an &nsub; anywhere, it will always be output (which is not so for &#10;)


There are other possibilities that have to do with linebreaking and proper indentation that are otherwise hard to achieve or may get lost in parameter passing as value-of instead of copy-of etc., but I am drifting too far away now from the OP's question....

(I wonder if this technique is used by others, too and for what purposes; I use similar tricks for easier handling of quote-escapes in source documents and outputting tab characters for indentation when normal indentation does not suffice)

-- Abel Braaksma

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-2011 All Rights Reserved.