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

Re: text output with some significant white space

Subject: Re: text output with some significant white space
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Thu, 19 Apr 2001 17:58:35 +0100
xsl text output
Hi Steve,

> I tried <xsl:text> to add spaces: <xsl:text> </xsl:text> will put a
> space in output but it isn't easy to visually distinguish one number
> of spaces from another. as needed for indention of say {3 6 9 12
> ...} spaces. It also balloons line out making very hard read.

OK... you could try using the concat() function with strings instead.
Note that the character entity reference &#xA; gives a line break:

<xsl:template match="foo">
   <xsl:value-of select="concat('begin ', name, ' {&#xA;',
                                '   ', body, '&#xA;',
                                '   }')" />
</xsl:template>

(Here I've maintained the initial lines - it's equivalent to:

<xsl:template match="foo">
   <xsl:value-of select="concat('begin ', name, ' {&#xA;   ',
                                body, '&#xA;   }')" />
</xsl:template>)

Alternatively, you could set a variable to the requisite number of
spaces, and then use that value:

<xsl:template match="foo">
   <xsl:variable name="indent" select="'   '" />
   <xsl:text />begin <xsl:value-of select="name" />{&#xA;<xsl:text />
   <xsl:value-of select="$indent" /><xsl:value-of select="body" />
   <xsl:text>&#xA;</xsl:text>
   <xsl:value-of select="$indent" />}<xsl:text />
</xsl:template>

If you made that a parameter, then you could change the level of the
indent as you called templates within it.  Note that I've used the
Allouche method in the above, with empty xsl:text elements delimiting
insignificant whitespace where it abuts significant characters.

Or obviously, a mixture of the two:

<xsl:template match="foo">
   <xsl:variable name="indent" select="'   '" />
   <xsl:value-of select="concat('begin ', name, '{&#xA;',
                                $indent, body, '&#xA;',
                                $indent, '}')" />
</xsl:template>

If you want to be more explicit about the length of the indent that
you're using, then you could use a variable holding loads of spaces,
and then use substring() to get the number of spaces that you want:

<xsl:variable name="spaces"
              select="'                                         '" />

<xsl:template match="foo">
   <xsl:variable name="indent" select="substring($spaces, 1, 3)" />
   ...
</xsl:template>

The above would give you indents of 3 spaces.

I hope that gives you some ideas,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.