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

Re: Problems copying elements recursively.

Subject: Re: Problems copying elements recursively.
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Mon, 10 Feb 2003 10:00:09 +0000
indent spaces
Dimitre wrote:
> "Imrran Wahid" <devguy2003@xxxxxxxxx> wrote in message
> news:20030209234334.51979.qmail@xxxxxxxxxxxxxxxxxxxxxxxxx
>> Pardon me for asking what may be a simple question,
>> but I am not very well versed in xsl. How do I
>> translate the count to number of spaces(&#160)?
>
> The simplest (to understand) way is to have an xsl:variable
> containing a sufficiently long string of spaces. Then take the exact
> number of spaces using the substring() function.
>
> Another way (when one doesn't know the maximum possible number of
> spaces that will be needed) is to use a recursive named template --
> e.g. one from exslt, or this one:
>
> http://sources.redhat.com/ml/xsl-list/2001-07/msg01040.html
>
> Or use the "iter" template from the FXSL library.
>
> The last solution is the most generic and can be used to implement
> any iteration of the type "Do something N times".

Just to add to Dimitre's suggestion: since Imrran is counting
ancestors to work out how many non-breaking spaces to add, it would be
a good idea to use one of the above methods to create an $indent
number of spaces (e.g. in an $indent-spaces global variable), and then
use xsl:for-each to iterate over the ancestors to multiply that number
of non-breaking spaces:

  <xsl:for-each select="ancestor::*">
    <xsl:value-of select="$indent-spaces" />
  </xsl:for-each>

Another method that I use when formatting a tree is to pass down the
previous indent as a parameter from parent to child, adding an indent
on each step. Something like:

<xsl:template match="*">
  <xsl:param name="indent" />
  ...
  <xsl:apply-templates>
    <xsl:with-param name="indent"
                    select="concat($indent, $indent-spaces)" />
  </xsl:apply-templates>
  ...
</xsl:template>

Again, the $indent-spaces that you add to the indent at each level may
need to be constructed dynamically from a number using one of
Dimitre's suggestions above.
  
Cheers,

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.