This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Indent based on position()
- From: Greg Faron <gfaron at integretechpub dot com>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Thu, 11 Apr 2002 10:13:15 -0600
- Subject: Re: [xsl] Indent based on position()
- References: <008001c1e14c$7012aa00$b123adc3@MWRWD9>
- Reply-to: xsl-list at lists dot mulberrytech dot com
At 09:10 AM 4/11/2002, you wrote:
><xsl:stylesheet version="1.0"
>xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
><xsl:output method="text"/>
><xsl:template match="/">
> <xsl:apply-templates select="content/line"/>
></xsl:template>
><xsl:template match="line">
> <!-- Concatenate with a bunch of dashes -->
> <xsl:variable name="dashes" select="'---------------------'"/>
> <!-- Take the number of dashes corresponding to the line's position
> number -->
> <xsl:value-of select="substring($dashes,1,position())"/>
> <xsl:value-of select="."/>
> <!-- Carriage-return-->
> <xsl:text> </xsl:text>
></xsl:template>
>
></xsl:stylesheet>
Not commenting on the efficiency of this algorithm, the above will only
work for a limited number of indentations (21 in this case). If you're
going to use this method, you'll need to conditionally grow the string as
in Jeni's str:padding template, located at
<http://www.exslt.org/str/functions/padding/str.padding.template.xsl>.
Greg Faron
Integre Technical Publishing Co.
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list