This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: text output with some significant white space


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]