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

Re: Is recursion in XSL really this difficult?

Subject: Re: Is recursion in XSL really this difficult?
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Tue, 17 Jul 2001 17:15:50 -0400
Re:  Is recursion in XSL really this difficult?
Hello Anonymous:

Ordinarily, I'm reluctant to answer posts from people who don't sign their name, since I like to have at least *some* clue of who they are.

But since I tackled a problem somewhat like yours back when in a project I distributed, I thought I'd post it.

Note that this recursive string-finding bit doesn't do a case-insensitive match, or make allowances for whitespace (which, judging from a cursory glance at your code, you apparently want). But it might give you a place to start.

Import this stylesheet into yours:

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<!-- The 'segmentfunc' named template returns, for a given node,
     a text string with all occurrences of a given substring
     isolated by markup. The substring to be isolated must be
     passed to the template as the 'find' parameter: its markup
     is provided by another named template, 'displayfound' (to
     be provided in the main stylesheet).

Wendell Piez, Mulberry Technologies, December 1999. -->

<xsl:template name="segmentfunc">
  <xsl:param name="procstring">
    <!-- the string to be processed. Trimmed recursively until
         all occurrences have been isolated and passed to
         'display'.                                           -->
    <xsl:value-of select="."/>
  </xsl:param>
  <xsl:choose>
    <xsl:when test="$find and contains($procstring, $find)">
      <xsl:value-of select="substring-before($procstring, $find)"/>
      <xsl:call-template name="displayfound"/>
      <xsl:call-template name="segmentfunc">
        <xsl:with-param name="procstring"
                      select="substring-after($procstring, $find)"/>
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$procstring"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

</xsl:stylesheet>

-- and then, place a template such as this one in your main stylesheet (to provide your found string with markup in the output) --

<xsl:template name="displayfound">
  <!-- Providing markup for the found string. -->
  <xsl:param name="displaystring"/>
  <b>
    <xsl:value-of select="$find"/>
  </b>
</xsl:template>

(This one wraps your found string in a <b> element, assuming that string is identified in a global variable or parameter $find; do what you will.)

I hope that helps.

--Wendell


====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================


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.