Re: [xsl] pattern matching in xslt

Subject: Re: [xsl] pattern matching in xslt
From: "Christopher R. Maden" <crism@xxxxxxxxx>
Date: Tue, 23 Apr 2002 13:56:01 -0700
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

At 13:32 23/4/02, David Nelson wrote:
>I would sincerely apprec. any help you might offer.  What I need to do is
>tokenize a node value into chunks, filter the trash and return in the xml,
>the new clean string. I'm a newbie with xslt and am having a tough time
>deciphering how to accomplish this.

This (string processing) is not XSLT's strong suit, which is probably why 
you're having trouble finding the cookbook solution.

There are two ways to approach it.  One, which is probably more efficient, 
is to use extension functions; you can just access the various Java string 
functions directly.

The "pure" way to do it is to use a recursive function; something like

<xsl:template match="description">
   <xsl:call-template name="process-text">
     <xsl:with-param name="string" select="."/>
   </xsl:call-template>
</xsl:template>

<xsl:template name="process-text">
   <xsl:param name="string" select="''"/>
   <xsl:choose>
     <xsl:when test="not(contains($string, '.. '))">
       <xsl:value-of select="$string"/>
     </xsl:when>
     <xsl:otherwise>
       <xsl:value-of
         select="substring-before($string, '.. ')"/>
       <xsl:call-template name="process-text">
         <xsl:with-param name="string"
           select="substring-after($string, '.. ')"/>
       </xsl:call-template>
     </xsl:otherwise>
   </xsl:choose>
</xsl:template>

~Chris
- -- 
Christopher R. Maden, Principal Consultant, crism consulting
DTDs/schemas - conversion - ebooks - publishing - Web - B2B - training
<URL: http://crism.maden.org/consulting/ >
PGP Fingerprint: BBA6 4085 DED0 E176 D6D4  5DFC AC52 F825 AFEC 58DA
-----BEGIN PGP SIGNATURE-----
Version: PGP Personal Privacy 6.5.8

iQA/AwUBPMXKYaxS+CWv7FjaEQJQOQCfVA0sWrqO0ZdVkbxLIwzFLuiHvewAoPaC
EwQ05fb7zzln0OwosWigNEO5
=m9AW
-----END PGP SIGNATURE-----


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread