xsl-list
[Top] [All Lists]

Re: [xsl] saxon xmlspy discrepancy in whitespace handling

2007-01-17 06:46:51
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

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--