[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] 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 
 gives a line break: <xsl:template match="foo"> <xsl:value-of select="concat('begin ', name, ' {
', ' ', body, '
', ' }')" /> </xsl:template> (Here I've maintained the initial lines - it's equivalent to: <xsl:template match="foo"> <xsl:value-of select="concat('begin ', name, ' {
 ', body, '
 }')" /> </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" />{
<xsl:text /> <xsl:value-of select="$indent" /><xsl:value-of select="body" /> <xsl:text>
</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, '{
', $indent, body, '
', $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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|