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: Looping over characters in a string


Hi Theodore,

> Is it possible to loop over characters in a string?

Jarno's shown you two ways of doing it using an increasing index.  The
third way is to use a recursive template that walks over the string,
removing the first character from the string with each recursion.  For
example:

<xsl:template name="add-X">
   <xsl:param name="string" select="." />
   <xsl:if test="$string">
      <xsl:text>X</xsl:text>
      <xsl:call-template name="add-X">
         <xsl:with-param name="string"
                         select="substring($string, 2)" />
      </xsl:call-template>
   </xsl:if>
</xsl:template>

How exactly you use this template depends on where you are to start
with. For example, you could use it in the template matching the tag
element (the advantage of this is that it means you don't have to pass
a parameter to the template, as I've set the default for the $string
parameter to be the string value of the current node).

<xsl:template match="tag">
   <xsl:call-template name="add-X" />
   <xsl:value-of select="." />
</xsl:template>

No ASCII art I'm afraid.  Hope that helps anyway,

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]