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

Re: Print number of chars depending upon int value

Subject: Re: Print number of chars depending upon int value
From: Elliotte Harold <elharo@xxxxxxxxxxxxxxx>
Date: Fri, 22 Apr 2005 07:11:08 -0400
how to print int value
Ranjan K. Baisak wrote:
select="substring('...................................',
1, $myLength)"/> should do the trick!

But if $myLength is greater than the number of chars in the string?


Like most things you'd accomplish with loops in traditional languages, this can be done in XSLT with recursion and named templates. Here's a simple stylesheet that prints 100 dots.


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>


  <xsl:template match="/">
    <xsl:call-template name="dots">
      <xsl:with-param name="count">100</xsl:with-param>
    </xsl:call-template>
 </xsl:template>

<xsl:template name="dots">

<xsl:param name="count" select="1"/>

        <xsl:if test="$count &gt; 0">
          <xsl:text>.</xsl:text>
          <xsl:call-template name="dots">
            <xsl:with-param name="count" select="$count -1"/>
          </xsl:call-template>
        </xsl:if>

</xsl:template>


</xsl:stylesheet>



Obviously if you could call the dots template with the count param set to a value provided by the input document rather than a constant as seen here.


--
Elliotte Rusty Harold  elharo@xxxxxxxxxxxxxxx
XML in a Nutshell 3rd Edition Just Published!
http://www.cafeconleche.org/books/xian3/
http://www.amazon.com/exec/obidos/ISBN=0596007647/cafeaulaitA/ref=nosim

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.